-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodegen.py
More file actions
executable file
·67 lines (52 loc) · 1.92 KB
/
codegen.py
File metadata and controls
executable file
·67 lines (52 loc) · 1.92 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
#!/usr/bin/python3
import os
import pathlib
def createFile(path, fname):
pathlib.Path(path).mkdir(parents=True, exist_ok=True)
fullname = os.path.join(path, fname)
open(fullname, 'w').close()
print(f'successfully created {fullname}')
def writeTemplateToFile(file, template):
with open(file, 'w') as f:
with open(template, 'r') as t:
f.write(t.read())
def getChallengeProblemName():
month = input('enter month\n')
weekNo = input('enter number of week\n')
rawProblemName = input('enter the name of the problem\n')
problemName = rawProblemName.replace(' ', '_')
return {
'path': os.path.join('30days-challenge', month, f'w{weekNo}'),
'fname': problemName + '.py'
}
def getCommonProblemName():
rawProblemName = input('enter the name of the problem')
problemName = rawProblemName.replace(' ', '_')
return {
'path': os.path.join(problemName),
'fname': 'solution.py'
}
def getCardProblemName():
cardName = input('enter the name of the card\n')
rawProblemName = input('enter the name of the problem')
problemName = rawProblemName.replace(' ', '_')
return {
'path': os.path.join(cardName),
'fname': problemName + '.py'
}
problemCreators = {
'challenge': getChallengeProblemName,
'card': getCardProblemName,
'common': getCommonProblemName
}
if __name__ == '__main__':
problemType = input('''enter type of problem you would like to solve
(can be only on of these: challenge, card, common)
In case any other type provided, common problem will be created
''')
creator = problemCreators.get(problemType, problemCreators['common'])
problemParameters = creator()
createFile(problemParameters['path'], problemParameters['fname'])
fullname = os.path.join(
problemParameters['path'], problemParameters['fname'])
writeTemplateToFile(fullname, 'codegen/template.py')