aocpy/get.py
felixm 3a915cb9e3 Start solving 2018 problems
I have also updated get.py to download the problems as
`d<day>.txt` instead of `i<day>.txt`. That allows me
to get the day input via `__input__.replace('.py', '.txt')`
which is a little more concise. I don't know why
I didn't do this earlier.
2024-07-04 11:10:27 -04:00

28 lines
724 B
Python
Executable File

#!/usr/bin/env python3
import sys
import requests
from keyring import get_password
if len(sys.argv) != 3:
print(f"Usage: {sys.argv[0]} <year> <day>")
sys.exit(1)
year = sys.argv[1]
day = sys.argv[2]
session_cookie = get_password('aoc-session-cookie', 'felixm')
assert session_cookie is not None
url = f"https://adventofcode.com/{year}/day/{day}/input"
cookies = {'session': session_cookie}
response = requests.get(url, cookies=cookies)
if response.status_code == 200:
filename = f"d{day}.txt"
with open(filename, 'w') as file:
file.write(response.text)
print(f"Year {year} {filename} written.")
else:
print(f"Error: Failed to download input (HTTP status code {response.status_code}).")