-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfetch.py
More file actions
32 lines (24 loc) · 713 Bytes
/
fetch.py
File metadata and controls
32 lines (24 loc) · 713 Bytes
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
from datetime import date
import sys
import os
import requests
import shutil
session = os.environ.get('AOC_SESSION')
if not session:
print("Missing AOC_SESSION env variable")
exit()
today = date.today()
day_num = today.day
if len(sys.argv) == 2:
day_num = int(sys.argv[1])
year = str(today.year)
day = "%02d" % day_num
if not os.path.exists(year):
os.makedirs(path)
remote_input_path = "https://adventofcode.com/" + year + "/day/" + str(day_num) + "/input"
f = open(year + "/day" + day + ".input", "w")
response = requests.get(remote_input_path, cookies={ "session" : session })
f.write(response.text)
f.close()
shutil.copyfile("day.template.py", year + "/day" + day + ".py")
print("Ready to go!")