Improved template

This commit is contained in:
Sven Heidemann 2022-11-30 12:20:28 +01:00
parent b0d483ea21
commit 7662154a04
3 changed files with 23 additions and 0 deletions

0
src/aoc/__init__.py Normal file
View File

20
src/aoc/aoc.py Normal file
View File

@ -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()

View File

@ -6,8 +6,11 @@ from cpl_query.enumerable import Enumerable
from cpl_query.extension import List from cpl_query.extension import List
from cpl_core.pipes import * from cpl_core.pipes import *
from aoc.aoc import get_input
# global vars # global vars
day = 0 day = 0
aoc_input = get_input(2022, day)
def main(): def main():