-
Notifications
You must be signed in to change notification settings - Fork 401
/
utility.py
76 lines (68 loc) · 2.66 KB
/
utility.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
67
68
69
70
71
72
73
74
75
76
# -*- coding:utf-8 -*-
import json
import codecs
from pprint import pprint
def addSolutionInfo(id):
"""
Add one solution of a competition
"""
with codecs.open('solutions.json', 'r', encoding='utf-8') as f:
solutions = json.load(f)
if str(id) in solutions.keys():
print("ID exsited, please try again")
return
algo = input("Enter algorithm: ")
code = input("Enter code: ")
s = {"algorithm": algo, "code": code}
solutions[id] = s
with codecs.open("solutions.json", 'w', encoding='utf-8') as f:
json.dump(solutions, f, indent=4, ensure_ascii=False)
def addCompe():
"""
Add a competition
"""
with codecs.open('competitions.json', 'r', encoding='utf-8') as f:
coms = json.load(f)
with codecs.open('solutions.json', 'r', encoding='utf-8') as f:
solutions = json.load(f)
cid = max([int(i) for i in solutions.keys()]) + 1
newCom = {}
for i in ["name", "link", "type", "platform", "hosts", "ddl"]:
newCom[i] = input("Enter %s: " % (i))
solution = []
num = input("How many solutins you find? ")
for i in range(int(num)):
rank = input("Rank: ")
print("The id of this solutions is %d" % (cid))
addSolutionInfo(cid)
solution.append({"rank": rank, "id": cid})
cid += 1
newCom["solutions"] = solution
coms.append(newCom)
with codecs.open("competitions.json", "w", encoding='utf-8') as f:
json.dump(coms, f, indent=4, ensure_ascii=False)
def renderToMK():
data = codecs.open("header.md", 'r', 'utf-8').readlines()
f = codecs.open("ReadMe.md", 'w', 'utf-8')
coms = json.load(codecs.open('competitions.json', encoding='utf-8'))
solutions = json.load(codecs.open('solutions.json', encoding='utf-8'))
for line in data:
f.write(line)
f.write("|名称|类型|截止日期|解决方案|平台|主办方| \n")
f.write("|--|--|--|--|--|--| \n")
for com in sorted(coms, key=lambda x: x['ddl'], reverse=True):
f.write("|[%s](%s)|%s|%s|"%( \
com['name'], com['link'], com['type'], com['ddl']))
soStrings = []
print(com['name'])
for solution in com['solutions']:
st = "第%s名 " % (solution['rank'])
so = solutions[str(solution['id'])]
if so['algorithm'] != "null" and so['algorithm'] != "":
st = "%s [算法](%s)" % (st, so['algorithm'])
if so['code'] != "null" and so['code'] != "":
st = "%s [代码](%s)" % (st, so['code'])
soStrings.append(st)
f.write('<br>'.join(soStrings))
f.write("|%s|%s| \n" % (com['platform'], com['hosts']))
f.close()