AdventOfCode/fetch.py

20 lines
518 B
Python
Raw Normal View History

from datetime import datetime
2019-12-02 13:59:18 +01:00
import os
import requests
import sys
if len(sys.argv) < 2:
2019-12-02 13:59:18 +01:00
print("Usage: <fetch> day")
sys.exit()
day = sys.argv[1]
year = sys.argv[2] if len(sys.argv) > 2 else str(datetime.now().year)
2019-12-02 13:59:18 +01:00
URL = "https://adventofcode.com/{}/day/{}/input"
2019-12-02 13:59:18 +01:00
SESSION_ID = os.environ["AOC_SESSION"]
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)