Last active
December 6, 2017 12:42
-
-
Save eivindbergem/f8afe402e25c2ff32f67fae6b33b2517 to your computer and use it in GitHub Desktop.
AoC input downloader
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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