-
Notifications
You must be signed in to change notification settings - Fork 0
/
new
executable file
·89 lines (64 loc) · 1.62 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
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
#!/usr/bin/env python3
import sys
import os
import fnmatch
NUM_AOC_DAYS = 25
if len(sys.argv) < 2:
print("Missing year argument. Please specify what year you wish to work on.")
sys.exit(1)
DIRECTORY = sys.argv[1]
# Check that the specified year has a directory already made.
matches = [file for file in os.listdir(".") if fnmatch.fnmatch(file, DIRECTORY)]
if len(matches) < 1:
print(f"No directory found for year {DIRECTORY}.")
sys.exit(1)
os.chdir(f"./{DIRECTORY}")
# Find the latest day completed within this year.
lastDay = int(sorted(os.listdir(f"./"))[-1][1:])
if lastDay >= NUM_AOC_DAYS:
print("No more days to complete for this year.")
sys.exit(1)
# Create a skeleton for the new day.
newDir = f"d{lastDay + 1}"
os.mkdir(f"./{newDir}")
os.chdir(f"./{newDir}")
open("input_1.txt", "w").close()
open("input_main.txt", "w").close()
with open("solution.py", "w") as f:
f.write(
f"""
import logging
import os
from dataclasses import dataclass
\"\"\"
PART 1
...
\"\"\"
\"\"\"
PART 2
...
\"\"\"
fileDir = os.path.dirname(os.path.realpath(\"__file__\"))
def getAbsolutePath(filename: str):
return os.path.join(fileDir, \"{DIRECTORY}/{newDir}\", filename)
def readInput(filename: str):
with open(getAbsolutePath(filename)) as f:
for line in f:
pass
"""
)
with open("test.py", "w") as f:
f.write(
"""
from solution import readInput
import logging
input1 = readInput(\"input_1.txt\")
mainInput = readInput(\"input_main.txt\")
def test_read_input():
assert False
def test_part_1():
assert False
def test_part_2():
assert False
"""
)