-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathget-input.py
executable file
·41 lines (34 loc) · 1.02 KB
/
get-input.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
#!/usr/bin/env python3
# ./get-input.py <year> <day>
# Uses https://pypi.org/project/advent-of-code-data/
import json
import os
import sys
import time
from pathlib import Path
from aocd.exceptions import PuzzleLockedError
from aocd.models import Puzzle, User
sessions_file = f"{Path.home()}/.advent-of-code.json"
with open(sessions_file) as f:
SESSIONS = json.load(f)
for session in SESSIONS:
if 'USED' in session['description']:
session_cookie = session['cookie']
break
# Prevent webbrowser.open, which aocd calls, from opening a browser:
os.environ["BROWSER"] = "true"
year = int(sys.argv[1])
day = int(sys.argv[2])
user = User(session_cookie)
puzzle = Puzzle(year=year, day=day, user=user)
while True:
try:
input_data = puzzle.input_data
break
except PuzzleLockedError:
print("Not unlocked yet..")
time.sleep(3)
input_file = f'src/year{year}/day{day:02}_input.txt'
with open(input_file, 'w') as f:
f.write(input_data)
print(f'DONE: {input_file}')