You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
518 B
20 lines
518 B
4 years ago
|
from datetime import datetime
|
||
5 years ago
|
import os
|
||
|
import requests
|
||
|
import sys
|
||
|
|
||
4 years ago
|
if len(sys.argv) < 2:
|
||
5 years ago
|
print("Usage: <fetch> day")
|
||
|
sys.exit()
|
||
|
day = sys.argv[1]
|
||
4 years ago
|
year = sys.argv[2] if len(sys.argv) > 2 else str(datetime.now().year)
|
||
5 years ago
|
|
||
4 years ago
|
URL = "https://adventofcode.com/{}/day/{}/input"
|
||
5 years ago
|
SESSION_ID = os.environ["AOC_SESSION"]
|
||
|
|
||
4 years ago
|
response = requests.get(URL.format(year, day), cookies={"session": SESSION_ID})
|
||
5 years ago
|
response.raise_for_status()
|
||
|
|
||
|
with open("day{}.txt".format(day), "wt") as output_file:
|
||
|
output_file.write(response.text)
|