-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathnew
executable file
·50 lines (35 loc) · 1.27 KB
/
new
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
#!/usr/bin/env python3
import sys
import os
argv = sys.argv
script_name = argv.pop(0)
if len(argv) != 3:
print(f"Usage: {script_name} challenge_name category points")
quit()
challenge = argv[0].strip()
category = argv[1].strip()
points = argv[2].strip()
assert points.isdigit() == True
if not os.path.exists('./Solved/'):
os.makedirs('./Solved/')
if not os.path.exists('./Unsolved/'):
os.makedirs('./Unsolved/')
folder = ''.join(c if c.isalnum() else '_' for c in challenge).rstrip('_')
folder_readme = folder + "/README.md"
already_created = (os.path.exists(folder_readme) or
os.path.exists('./Solved/' + folder_readme) or
os.path.exists('./Unsolved/' + folder_readme))
if already_created:
print('Already created')
else:
if not os.path.exists(folder):
os.makedirs(folder)
with open("TEMPLATE.md", 'r') as f:
template = f.read()
with open(folder + "/README.md", 'w') as f2:
template = template.replace("CHALLENGE", challenge)
template = template.replace("CATEGORY", category)
template = template.replace("POINTS", points)
f2.write(template)
with open("README.md", 'a') as f3:
f3.write(f'[{challenge}](./Solved/{folder}) | {category} | {points} | \n')