forked from william-fecteau/AdventOfCodePythonFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
74 lines (60 loc) · 2.26 KB
/
main.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
import sys
import os
import shutil
import time
from dotenv import load_dotenv
from days import *
from utils.aoc_utils import AOCDay, AOCDays
if __name__ == "__main__":
load_dotenv() # take environment variables from .env.
year = os.getenv('AOC_YEAR')
sessionToken = os.getenv('AOC_SESSION_COOKIE')
# Getting parameters
runAll = False
dayNumber = 1
if len(sys.argv) >= 2:
try:
if sys.argv[1] == "all":
runAll = True
else:
dayNumber = int(sys.argv[1])
except Exception:
print("{} - Run aoc solutions".format(sys.argv[0]))
print("Usage: {} [day]".format(sys.argv[0]))
sys.exit(1)
else:
print("{} - Run aoc solutions".format(sys.argv[0]))
print("Usage: {} [day]".format(sys.argv[0]))
sys.exit(1)
# Validation
relPath = "/days/day" + str(dayNumber) + ".py"
if dayNumber <= 0 or dayNumber > 25:
print("Day must be between 0 and 25")
sys.exit(1)
# If day file does not exist, create it
elif not os.path.exists(os.getcwd() + relPath):
# Copying template file
shutil.copy(os.getcwd() + "/days/_template.py", os.getcwd() + relPath)
# Renaming template
fin = open(os.getcwd() + relPath, "rt")
data = fin.read()
data = data.replace("@day(0)", "@day(" + str(dayNumber) + ")").replace("DayTemplate", "Day" + str(dayNumber))
fin.close()
# Overriding day file
fin = open(os.getcwd() + relPath, "wt")
fin.write(data)
fin.close()
print("Day "+ str(dayNumber) + " created! glhf")
# Else we run it normally
else:
if runAll:
startTime = time.time()
for dayNum in [x+1 for x in range(17)]:
curDay : AOCDay = AOCDays.getInstance().getDay(dayNum)
inst = curDay(year, dayNum, sessionToken, False)
inst.run()
totalTime = time.time() - startTime
print("Grand total (ms):", totalTime)
else:
curDay : AOCDay = AOCDays.getInstance().getDay(dayNumber)
curDay(year, dayNumber, sessionToken, True).run()