-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_puzzle_input.py
More file actions
48 lines (41 loc) · 1.67 KB
/
get_puzzle_input.py
File metadata and controls
48 lines (41 loc) · 1.67 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
import os.path
import sys
import aocd.exceptions
from aocd.models import Puzzle
from aocd.get import most_recent_year
from time import sleep
def main():
print(sys.argv)
year_str = sys.argv[1] if len(sys.argv) > 1 else input("Year: ")
year = most_recent_year() if year_str == 'default' else int(year_str)
try:
for day in range(1, 26):
puzzle = Puzzle(day=day, year=year)
read = False
# Main Input File
filepath = f"./puzzles/{year}/inputs/day{day:02}_input.txt"
if not os.path.isfile(filepath):
print(f"Reading day Input {day}")
input_data = puzzle.input_data
with open(filepath, "w") as f:
f.write(input_data)
read = True
# Example Files
if not (os.path.isfile(f"./puzzles/{year}/inputs/day{day:02}_sample_input.txt") or
os.path.isfile(f"./puzzles/{year}/inputs/day{day:02}_sample1_input.txt")):
print(f"Reading day Example {day}")
example_data = puzzle.examples
for i, data in enumerate(ex.input_data for ex in example_data):
filepath = (f"./puzzles/{year}/inputs/day{day:02}_sample"
f"{i+1 if len(example_data) > 1 else ''}_input.txt")
if not os.path.isfile(filepath):
with open(filepath, "w") as f:
f.write(data)
read = True
if read:
print("\tDone")
sleep(2)
except aocd.exceptions.PuzzleLockedError:
pass
if __name__ == "__main__":
main()