Cool set of tools for working with Advent of Code challenges
Project description
advent-tools
Python interface to conveniently download and interact with advent data with a high-level-wrapper.
Installation
A Virtual Environment is strongly recommended to install the library
# Linux/macOS
python3 -m pip install -U advent-tools
# Windows
py -3 -m pip install -U advent-tools
Quickstart
First we need to get the session cookie (🍪), in order to do that
- Open your broswer's Devtools (Chrome / Firefox guide)
- Head on over to
Applicationtab, then toCookies - Find and copy
sessioncookie value - set
AOC_SESSION=<session-cookie-value>environment variable (make sure terminal restart doesn't reset the value)
OR
Enter the following command in your terminal which will create an.envfile storing your session cookie.
# Same for all Windows, Linux and macOS
echo AOC_SESSION=<session-cookie-value> > .env
# Make sure to replace <session-cookie-value> with your cookie value
Make sure version control system ignores your token container in case you are using one, cause your token is sensitive and can be used for log-ins.
Usage
year and day can be given as kwargs when subclassing advent.Advent or can be provided using it's __getitem__ behaviour like Advent[year:day]
from advent import Advent
class Solution(Advent, year=2020, day=3):
def __init__(self, data: str) -> None:
self.data = ...
def part_1(self):
...
def part_2(self):
...
Example 1:
from advent import Advent
class Solution(Advent, year=2022, day=2):
PLAY = {"A": ["Z", "X", "Y"], "B": ["X", "Y", "Z"], "C": ["Y", "Z", "X"]}
def __init__(self, data: str) -> None:
self.data = [line.split() for line in data.splitlines()]
def part_1(self):
return sum(self.PLAY[oppo].index(me) * 3 + ord(me) - 87 for oppo, me in self.data)
def part_2(self):
return sum((fate := ord(res) - 88) * 3 + ord(self.PLAY[oppo][fate]) - 87 for oppo, res in self.data)
Example 2:
from heapq import nlargest
from advent import Advent
class Solution(Advent[2022:1]):
def __init__(self, data: str) -> None:
self.max, *self.top = nlargest(3, [sum(map(int, chunk.split())) for chunk in data.split("\n\n")])
def part_1(self):
return self.max
def part_2(self):
return self.max + sum(self.top)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file advent_tools-1.0.0b1.tar.gz.
File metadata
- Download URL: advent_tools-1.0.0b1.tar.gz
- Upload date:
- Size: 374.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de2e8c3509a9bd73e4d516eb5a2b5bd618054860e5c880a90e30566a7d5e9879
|
|
| MD5 |
86631722e286ae0552f61d68322a33fc
|
|
| BLAKE2b-256 |
073578b6d5178c47b4e58244b221fc1139ba3aec631268441639a7e4dfced1c0
|
Provenance
The following attestation bundles were made for advent_tools-1.0.0b1.tar.gz:
Publisher:
publish.yml on Achxy/advent-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
advent_tools-1.0.0b1.tar.gz -
Subject digest:
de2e8c3509a9bd73e4d516eb5a2b5bd618054860e5c880a90e30566a7d5e9879 - Sigstore transparency entry: 154513405
- Sigstore integration time:
-
Permalink:
Achxy/advent-tools@0a16d6a41f9a071f4c2f6ad8cc4bd1e300962d47 -
Branch / Tag:
refs/tags/v1.0.0b1 - Owner: https://github.com/Achxy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0a16d6a41f9a071f4c2f6ad8cc4bd1e300962d47 -
Trigger Event:
push
-
Statement type:
File details
Details for the file advent_tools-1.0.0b1-py3-none-any.whl.
File metadata
- Download URL: advent_tools-1.0.0b1-py3-none-any.whl
- Upload date:
- Size: 14.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a46ea7517832a8226506d13be50eb587f651308e6525003a6f1285ef3af89f3
|
|
| MD5 |
c66ed3c9e9113e00a0495045ae28a40d
|
|
| BLAKE2b-256 |
c1fe4fc3249a280a8e473d28c176e08ef6245b6a6090235f1335cbb0dc7ad515
|
Provenance
The following attestation bundles were made for advent_tools-1.0.0b1-py3-none-any.whl:
Publisher:
publish.yml on Achxy/advent-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
advent_tools-1.0.0b1-py3-none-any.whl -
Subject digest:
3a46ea7517832a8226506d13be50eb587f651308e6525003a6f1285ef3af89f3 - Sigstore transparency entry: 154513407
- Sigstore integration time:
-
Permalink:
Achxy/advent-tools@0a16d6a41f9a071f4c2f6ad8cc4bd1e300962d47 -
Branch / Tag:
refs/tags/v1.0.0b1 - Owner: https://github.com/Achxy
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@0a16d6a41f9a071f4c2f6ad8cc4bd1e300962d47 -
Trigger Event:
push
-
Statement type: