From 7662154a04af99f2deb096df75613ece864de059 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 30 Nov 2022 12:20:28 +0100 Subject: [PATCH] Improved template --- src/aoc/__init__.py | 0 src/aoc/aoc.py | 20 ++++++++++++++++++++ src/template_dayX.py | 3 +++ 3 files changed, 23 insertions(+) create mode 100644 src/aoc/__init__.py create mode 100644 src/aoc/aoc.py 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():