-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathrun.py
66 lines (53 loc) · 2.13 KB
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# -*- coding: UTF-8 -*-.
import json
import os
import urllib.parse
cv = './InfoCenter/cv.json'
nlp = './InfoCenter/nlp.json'
dm = './InfoCenter/data_mining.json'
# ongoing = './InfoCenter/ongoing.json'
base_url = "https://github.com/AI-Sphere/Awesome-Noah/tree/master/"
header_tmp = """
# {}
比赛链接:{}
## 解决方案
|排名|地址|
|----|----|
"""
def generate_sub_md(path, prefix='NLP'):
try:
contents = json.load(open('%s' % path, encoding='utf-8'))
except:
print("JSON FORMAT ERROR: please check your %s file." % path)
exit(1)
res_dct = {}
for content in contents:
os.makedirs('{}/{}'.format(prefix, content['title']), exist_ok=True)
with open('{}/{}/readme.md'.format(prefix, content['title']), 'w') as fout:
if not content['game link']:
content['game link'] = 'You can search it on baidu or google.'
concat_md = header_tmp.format(content['title'], content['game link'])
for k, v in content['solutions'].items():
if type(v) is list:
v = '<br>'.join(v)
concat_md += "|{}|{}|\n".format(k, v)
fout.write(concat_md)
encoded_prefix = urllib.parse.quote(prefix)
encoded_title = urllib.parse.quote(content['title'])
concat_url = base_url + '{}/{}'.format(encoded_prefix, encoded_title)
res_dct[(content['title'], concat_url)] = len(content['solutions'])
return [i[0] for i in sorted(res_dct.items(), key=lambda d:d[1], reverse=True)]
def generate_home_md(contents):
md = '\n'.join([' - [{}]({})'.format(c[0], c[1]) for c in contents])
return md
cv = generate_sub_md(cv, 'CV')
nlp = generate_sub_md(nlp, 'NLP')
dm = generate_sub_md(dm, 'Data Mining')
# ongoing = generate_sub_md(ongoing, 'Ongoing')
with open('./res/home_templete.md', 'r') as fin, open('readme.md', 'w') as fout:
s = ''.join(fin.readlines())
# ongoing_1 = '\n'.join(['- [{}]({})'.format(c[0], c[1]) for c in ongoing])
nlp = generate_home_md(nlp)
cv = generate_home_md(cv)
dm = generate_home_md(dm)
fout.write(s.format(nlp, cv, dm))