diff --git a/src/aoc/__init__.py b/src/aoc/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/aoc/aoc.py b/src/aoc/aoc.py new file mode 100644 index 0000000..53b25d6 --- /dev/null +++ b/src/aoc/aoc.py @@ -0,0 +1,20 @@ +import os +import urllib.request + + +def _get_cookie_headers() -> dict[str, str]: + """ + original code from https://github.com/anthonywritescode/aoc2022/blob/main/support/support.py + """ + with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../.env')) as f: + contents = f.read().strip() + return {'Cookie': contents} + + +def get_input(year: int, day: int) -> str: + """ + original code from https://github.com/anthonywritescode/aoc2022/blob/main/support/support.py + """ + url = f'https://adventofcode.com/{year}/day/{day}/input' + req = urllib.request.Request(url, headers=_get_cookie_headers()) + return urllib.request.urlopen(req).read().decode() diff --git a/src/template_dayX.py b/src/template_dayX.py index 329bcfe..cda6c63 100644 --- a/src/template_dayX.py +++ b/src/template_dayX.py @@ -6,8 +6,11 @@ from cpl_query.enumerable import Enumerable from cpl_query.extension import List from cpl_core.pipes import * +from aoc.aoc import get_input + # global vars day = 0 +aoc_input = get_input(2022, day) def main():