-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
84 lines (62 loc) · 1.92 KB
/
setup.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
#!/usr/bin/python3
import os
import requests
import sys
structure_template = 'src/{}/kotlin/solutions/day{}'
solver_template = """
package solutions.{package}
import solutions.Solver
class {clazz}: Solver {{
override fun solve(input: List<String>, partTwo: Boolean): String {{
TODO("not implemented")
}}
}}
"""
test_template = """
package solutions.{package}
import solutions.AbstractDayTest
class {clazz}Test: AbstractDayTest({clazz}()) {{
override fun getPart1Data(): List<TestData> = listOf(
TestData(listOf(""), "")
)
override fun getPart2Data(): List<TestData> = listOf(
TestData(listOf(""), "")
)
}}
"""
def generate_files(day, kind, template):
day_as_string = str(day).zfill(2)
clazz = 'Day{}'.format(day)
package = 'day{}'.format(day_as_string)
folder = structure_template.format(kind, day_as_string)
os.makedirs(folder)
suffix = ''
if kind == 'test':
suffix = 'Test'
path = "{}/{}.{}".format(folder, clazz+suffix, 'kt')
content = template.format(package=package, clazz=clazz)
with open(path, 'w') as f:
f.write(content)
return folder
def fetch_input(day, token, folder):
url = 'https://adventofcode.com/2017/day/{}/input'.format(day)
res = requests.get(url, cookies={'session': token})
input_file = '{}/input'.format(folder)
with open(input_file, 'wb') as f:
for chunk in res.iter_content(chunk_size=128):
f.write(chunk)
if __name__ == '__main__':
if len(sys.argv) != 3:
print("Usage: setup.py token day")
exit(1)
token = sys.argv[1]
day = sys.argv[2]
day_int = -1
try:
day_int = int(day)
except ValueError:
print("Could not parse day as number: [{}]".format(day))
exit(1)
folder = generate_files(day_int, 'main', solver_template)
generate_files(day_int, 'test', test_template)
fetch_input(day_int, token, folder)