advent-tools


Nameadvent-tools JSON
Version 1.0.0b1 PyPI version JSON
download
home_pageNone
SummaryCool set of tools for working with Advent of Code challenges
upload_time2024-12-10 17:10:47
maintainerNone
docs_urlNone
authorNone
requires_python>=3.13
licenseNone
keywords advent advent of code advent tools aoc
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # [advent-tools](https://github.com/Achxy/advent-tools)
Python interface to conveniently download and interact with advent data with a high-level-wrapper.

### Installation
A [Virtual Environment](https://docs.python.org/3/library/venv.html) is strongly recommended to install the library

```bash
# 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
1) Open your broswer's Devtools ([Chrome](https://developer.chrome.com/docs/devtools/open) / [Firefox](https://firefox-source-docs.mozilla.org/devtools-user/) guide)
2) Head on over to `Application` tab, then to `Cookies`
3) Find and copy `session` cookie value
!["Steps to get session cookie"](./assets/steps_to_get_session_cookie.jpg)
4) 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 `.env` file storing your session cookie.
```bash
# 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]`
```py
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:
```py
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:
```python
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)
```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "advent-tools",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.13",
    "maintainer_email": null,
    "keywords": "advent, advent of code, advent tools, aoc",
    "author": null,
    "author_email": "Achyuth Jayadevan <achyuth@jayadevan.in>",
    "download_url": "https://files.pythonhosted.org/packages/07/35/78b6d5178c47b4e58244b221fc1139ba3aec631268441639a7e4dfced1c0/advent_tools-1.0.0b1.tar.gz",
    "platform": null,
    "description": "# [advent-tools](https://github.com/Achxy/advent-tools)\nPython interface to conveniently download and interact with advent data with a high-level-wrapper.\n\n### Installation\nA [Virtual Environment](https://docs.python.org/3/library/venv.html) is strongly recommended to install the library\n\n```bash\n# Linux/macOS\npython3 -m pip install -U advent-tools\n\n# Windows\npy -3 -m pip install -U advent-tools\n```\n\n---\n### Quickstart\nFirst we need to get the `session` cookie (\ud83c\udf6a), in order to do that\n1) Open your broswer's Devtools ([Chrome](https://developer.chrome.com/docs/devtools/open) / [Firefox](https://firefox-source-docs.mozilla.org/devtools-user/) guide)\n2) Head on over to `Application` tab, then to `Cookies`\n3) Find and copy `session` cookie value\n![\"Steps to get session cookie\"](./assets/steps_to_get_session_cookie.jpg)\n4) set `AOC_SESSION=<session-cookie-value>` environment variable (make sure terminal restart doesn't reset the value)\\\n**OR**\\\nEnter the following command in your terminal which will create an `.env` file storing your session cookie.\n```bash\n# Same for all Windows, Linux and macOS\necho AOC_SESSION=<session-cookie-value> > .env\n# Make sure to replace <session-cookie-value> with your cookie value\n```\nMake 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.\n\n---\n### Usage\n`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]`\n```py\nfrom advent import Advent\n\n\nclass Solution(Advent, year=2020, day=3):\n    def __init__(self, data: str) -> None:\n        self.data = ...\n\n    def part_1(self):\n        ...\n\n    def part_2(self):\n        ...\n```\nExample 1:\n```py\nfrom advent import Advent\n\n\nclass Solution(Advent, year=2022, day=2):\n    PLAY = {\"A\": [\"Z\", \"X\", \"Y\"], \"B\": [\"X\", \"Y\", \"Z\"], \"C\": [\"Y\", \"Z\", \"X\"]}\n\n    def __init__(self, data: str) -> None:\n        self.data = [line.split() for line in data.splitlines()]\n\n    def part_1(self):\n        return sum(self.PLAY[oppo].index(me) * 3 + ord(me) - 87 for oppo, me in self.data)\n\n    def part_2(self):\n        return sum((fate := ord(res) - 88) * 3 + ord(self.PLAY[oppo][fate]) - 87 for oppo, res in self.data)\n```\nExample 2:\n```python\nfrom heapq import nlargest\nfrom advent import Advent\n\nclass Solution(Advent[2022:1]):\n    def __init__(self, data: str) -> None:\n        self.max, *self.top = nlargest(3, [sum(map(int, chunk.split())) for chunk in data.split(\"\\n\\n\")])\n\n    def part_1(self):\n        return self.max\n\n    def part_2(self):\n        return self.max + sum(self.top)\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Cool set of tools for working with Advent of Code challenges",
    "version": "1.0.0b1",
    "project_urls": {
        "Bug Tracker": "https://github.com/Achxy/advent-tools/issues",
        "Repository": "https://github.com/Achxy/advent-tools.git"
    },
    "split_keywords": [
        "advent",
        " advent of code",
        " advent tools",
        " aoc"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c1fe4fc3249a280a8e473d28c176e08ef6245b6a6090235f1335cbb0dc7ad515",
                "md5": "c66ed3c9e9113e00a0495045ae28a40d",
                "sha256": "3a46ea7517832a8226506d13be50eb587f651308e6525003a6f1285ef3af89f3"
            },
            "downloads": -1,
            "filename": "advent_tools-1.0.0b1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c66ed3c9e9113e00a0495045ae28a40d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.13",
            "size": 14521,
            "upload_time": "2024-12-10T17:10:45",
            "upload_time_iso_8601": "2024-12-10T17:10:45.610517Z",
            "url": "https://files.pythonhosted.org/packages/c1/fe/4fc3249a280a8e473d28c176e08ef6245b6a6090235f1335cbb0dc7ad515/advent_tools-1.0.0b1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "073578b6d5178c47b4e58244b221fc1139ba3aec631268441639a7e4dfced1c0",
                "md5": "86631722e286ae0552f61d68322a33fc",
                "sha256": "de2e8c3509a9bd73e4d516eb5a2b5bd618054860e5c880a90e30566a7d5e9879"
            },
            "downloads": -1,
            "filename": "advent_tools-1.0.0b1.tar.gz",
            "has_sig": false,
            "md5_digest": "86631722e286ae0552f61d68322a33fc",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.13",
            "size": 374323,
            "upload_time": "2024-12-10T17:10:47",
            "upload_time_iso_8601": "2024-12-10T17:10:47.777473Z",
            "url": "https://files.pythonhosted.org/packages/07/35/78b6d5178c47b4e58244b221fc1139ba3aec631268441639a7e4dfced1c0/advent_tools-1.0.0b1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-10 17:10:47",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Achxy",
    "github_project": "advent-tools",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "advent-tools"
}
        
Elapsed time: 0.40797s