-
Notifications
You must be signed in to change notification settings - Fork 0
/
AC.py
100 lines (82 loc) · 2.95 KB
/
AC.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
leetcode ac script
desc:
"""
import os
from time import gmtime, strftime
if __name__ == '__main__':
num = input('请输入ID:')
if num.isdigit():
num = '0' * (4 - len(str(num))) + num
chinese_name = input('请输入中文题目(chinese_name):')
englist_name = input('请输入英文题目(english_name):')
LAN = input('请输入AC语言(default: java):')
if LAN.strip() == '':
LAN = 'java'
print(LAN)
else:
LAN = LAN.lower()
DIFFICULTY = input('请输入难度(default: easy):')
if DIFFICULTY.strip() == '':
DIFFICULTY = 'easy'
print(DIFFICULTY)
else:
if DIFFICULTY == '简单' or DIFFICULTY == '1':
DIFFICULTY = 'easy'
elif DIFFICULTY == '中等' or DIFFICULTY == '2':
DIFFICULTY = 'medium'
elif DIFFICULTY == '困难' or DIFFICULTY == '3':
DIFFICULTY = 'hard'
DIFFICULTY = DIFFICULTY.lower()
path = os.getcwd() + '/all/' + num + '.' + englist_name
if LAN == 'c++':
FILE_TYPE = 'cpp'
elif LAN == 'python':
FILE_TYPE = 'py'
else:
FILE_TYPE = LAN
file_name = 'Solution.' + FILE_TYPE
if not os.path.exists(path):
os.makedirs(path)
FILE_PATH = ""
if not os.path.exists(path + '/' + file_name):
FILE_PATH = path + '/' + file_name
file = open(FILE_PATH, 'w')
file.close()
else:
FILE_PATH = path + '/' + 'Solution_' + \
strftime("%Y-%m-%d-%H-%M-%S", gmtime())+'.' + FILE_TYPE
file = open(FILE_PATH, 'w')
file.close()
dir_path = './all/' + num + '.' + englist_name
readme_txt = '|' + num + '| [' + chinese_name + '](./all/' + num + '.' + englist_name + \
') | [' + englist_name + '](./all/' + num + '.' + englist_name + \
') | ' + DIFFICULTY + ' | ' + LAN + ' |'
print(readme_txt)
commit_msg = '✔ ' + num + ' ' + chinese_name + ' AC use ' + LAN
print(commit_msg)
# update problems infomation to README.md
with open("README.md", "r", encoding='utf-8') as f:
content = f.readlines()
if num.isnumeric():
for i, line in enumerate(content):
if line.startswith('|'):
cur = line.split('|')[1].strip()
if cur.isnumeric():
cur = int(cur)
if cur > int(num):
content.insert(i, readme_txt + '\n')
break
else:
content.insert(len(content) + 1, readme_txt + '\n')
with open("README.md", "w", encoding='utf-8') as f:
f.writelines(content)
# open file in current vscode window
os.system('code -r ' + FILE_PATH)
# wait for write code to the file
os.system('pause')
# commit ac code and push to github
os.system('git add ' + dir_path)
os.system('git add README.md')
os.system('git commit -m "' + commit_msg + '"')
os.system('git push')