Skip to content

Instantly share code, notes, and snippets.

@eivindbergem
Last active December 6, 2017 12:42
Show Gist options
  • Save eivindbergem/f8afe402e25c2ff32f67fae6b33b2517 to your computer and use it in GitHub Desktop.
Save eivindbergem/f8afe402e25c2ff32f67fae6b33b2517 to your computer and use it in GitHub Desktop.
AoC input downloader
import os.path
import requests
SESSION_COOKIE = "" # Add your session cookie here
URL = "http://adventofcode.com/2017/day/{}/input"
def download(day, filename):
r = requests.get(
URL.format(day),
cookies=dict(session=SESSION_COOKIE))
if r.status_code != 200:
raise Exception(r.text)
with open(filename, "w") as fd:
fd.write(r.text)
def get_input(day):
filename = "{:02}-input.txt".format(day)
if not os.path.isfile(filename):
download(day, filename)
with open(filename) as fd:
for line in fd:
yield line
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment