2019-12-22 01:28:04 +01:00
|
|
|
from datetime import datetime
|
2019-12-02 13:59:18 +01:00
|
|
|
import os
|
|
|
|
import requests
|
|
|
|
import sys
|
|
|
|
|
2019-12-22 01:28:04 +01:00
|
|
|
if len(sys.argv) < 2:
|
2019-12-02 13:59:18 +01:00
|
|
|
print("Usage: <fetch> day")
|
|
|
|
sys.exit()
|
|
|
|
day = sys.argv[1]
|
2019-12-22 01:28:04 +01:00
|
|
|
year = sys.argv[2] if len(sys.argv) > 2 else str(datetime.now().year)
|
2019-12-02 13:59:18 +01:00
|
|
|
|
2019-12-22 01:28:04 +01:00
|
|
|
URL = "https://adventofcode.com/{}/day/{}/input"
|
2019-12-02 13:59:18 +01:00
|
|
|
SESSION_ID = os.environ["AOC_SESSION"]
|
|
|
|
|
2019-12-22 01:28:04 +01:00
|
|
|
response = requests.get(URL.format(year, day), cookies={"session": SESSION_ID})
|
2019-12-02 13:59:18 +01:00
|
|
|
response.raise_for_status()
|
|
|
|
|
|
|
|
with open("day{}.txt".format(day), "wt") as output_file:
|
|
|
|
output_file.write(response.text)
|