- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit.py
More file actions
Latest commit
104 lines (81 loc) · 3.44 KB
/
Copy pathcommit.py
File metadata and controls
104 lines (81 loc) · 3.44 KB
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
101
102
103
104
importos
importdatetime
git_content=""
new_q_template="""
### number [][]()
问题描述:
示例:
\`\`\`
\`\`\`
解法:
"""
defupdate_resolve_num():
cmd="find src/main/java -type f | grep -E 'hard|easy|medium' |wc -l"
resolve_num=os.popen(cmd).readlines()[0].replace(' ', '').replace('\n', '')
cmd="sed -ig \"s/累计总数: [0-9]*$/累计总数: "+resolve_num+"/\" README.md"
os.system(cmd)
cmd="find src/main/java -type f | grep 'easy' |wc -l"
resolve_num=os.popen(cmd).readlines()[0].replace(' ', '').replace('\n', '')
cmd="sed -ig \"s/| Easy | [0-9]* |$/| Easy | "+resolve_num+" |/\" README.md"
os.system(cmd)
cmd="find src/main/java -type f | grep 'medium' |wc -l"
resolve_num=os.popen(cmd).readlines()[0].replace(' ', '').replace('\n', '')
cmd="sed -ig \"s/| Medium | [0-9]* |$/| Medium | "+resolve_num+" |/\" README.md"
os.system(cmd)
cmd="find src/main/java -type f | grep 'hard' |wc -l"
resolve_num=os.popen(cmd).readlines()[0].replace(' ', '').replace('\n', '')
cmd="sed -ig \"s/| Hard | [0-9]* |$/| Hard | "+resolve_num+" |/\" README.md"
os.system(cmd)
defadd_solutions():
today=str(datetime.date.today())
cmd="grep -o '^| \d\{4\}-\d\{2\}-\d\{2\} | .* |$' README.md"
events=os.popen(cmd).readlines()
already_content=""
foreventinevents:
day=event.split('|')[1].strip()
content=event.split('|')[2].strip()
ifday==today:
already_content=content
cmd="git ls-files . --exclude-standard --others | grep -v \"out\" | grep \"Solution\""
files=os.popen(cmd).readlines()
new_files= {}
update_md_files= []
forfileinfiles:
type=file.split('/')[5]
md_file="src/main/resources/"+type+".md"
update_md_files.append(md_file)
level=file.split('/')[6].upper()
num=int(file.split('/')[7].split('.java')[0].replace('Solution', ''))
cmd="sed -ig \"s/^### "+str(num) +" \[\]\[\(.*\)\]()$/### "+str(num) +" \["+level+"\]\[\\1\]\("+file.replace('src/main', '..').replace('/', '\/').replace('\n', '') +"\)/\" "+md_file
os.system(cmd)
new_files[num] =type
formd_fileinset(update_md_files):
cmd="echo \""+new_q_template+"\" >> "+md_file
os.system(cmd)
ifnew_files: # 如果有新文件,则更新README.md
content=""
globalgit_content
forkeyinsorted(new_files.keys()):
content+="["+str(key) +"](src/main/resources/"+new_files[key] +".md), "
git_content=git_content+",Solution"+str(key)
content=content[:-2]
ifalready_content!="": # 如果已有则替换
content=already_content+", "+content
cmd="sed -ig \"s/"+already_content.replace('/', '\/') +"/"+content.replace('/', '\/') +"/\" README.md"
cmd=cmd.replace('[', '\[').replace(']', '\]')
else: # 否则新增
content="| "+today+" | "+content+" |"
cmd="echo \""+content+"\" >> README.md"
os.system(cmd)
defgit_add_commit_push():
cmd="git add ."
os.system(cmd)
cmd="git commit -m \""+git_content+"\""
os.system(cmd)
cmd="git push origin master:master"
os.system(cmd)
if__name__=="__main__":
add_solutions()
update_resolve_num()
git_add_commit_push()