From ee0d318364e51c6e68ef6e913b5baa975fe316b9 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Thu, 1 Dec 2022 07:29:36 +0100 Subject: [PATCH] day 1 --- README.md | 8 +++++++- deps.txt | 3 +++ src/aoc/aoc.py | 8 +++++++- 3 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 deps.txt diff --git a/README.md b/README.md index 02592f0..a786c7e 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,14 @@ https://adventofcode.com/2022 +Original at: https://git.sh-edraft.de/edraft/adventofcode-2022.git + +## Session + +Save the session key from https://adventofcode.com/ to .env file in the variable ```session=``` + ## Execute -First create a venv and install deps with ```pip install -t deps.txt``` +First create a venv and install deps with ```pip install -r deps.txt --extra-index-url https://pip.sh-edraft.de``` Then run code easily with ```./run {Number-of-day}``` \ No newline at end of file diff --git a/deps.txt b/deps.txt new file mode 100644 index 0000000..9ccabc6 --- /dev/null +++ b/deps.txt @@ -0,0 +1,3 @@ +cpl-cli==2022.10.1 +cpl-core==2022.10.0.post9 +cpl-query==2022.10.0.post2 diff --git a/src/aoc/aoc.py b/src/aoc/aoc.py index 53b25d6..a239b88 100644 --- a/src/aoc/aoc.py +++ b/src/aoc/aoc.py @@ -1,12 +1,18 @@ import os import urllib.request +from cpl_core.console import Console + 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: + env = os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../.env') + if not os.path.exists(env): + Console.error(f'Session key from https://adventofcode.com/ required') + + with open(env) as f: contents = f.read().strip() return {'Cookie': contents}