advent-of-code-data 2.0.0__tar.gz → 2.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/PKG-INFO +15 -6
  2. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/README.rst +6 -4
  3. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/advent_of_code_data.egg-info/PKG-INFO +15 -6
  4. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/advent_of_code_data.egg-info/SOURCES.txt +2 -0
  5. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/advent_of_code_data.egg-info/requires.txt +1 -1
  6. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/__init__.py +24 -1
  7. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/_ipykernel.py +2 -1
  8. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/cli.py +2 -2
  9. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/cookies.py +16 -5
  10. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/examples.py +22 -14
  11. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/get.py +14 -5
  12. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/models.py +90 -59
  13. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/post.py +17 -3
  14. advent_of_code_data-2.0.2/aocd/py.typed +0 -0
  15. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/runner.py +34 -17
  16. advent_of_code_data-2.0.2/aocd/types.py +35 -0
  17. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/utils.py +49 -13
  18. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/pyproject.toml +22 -2
  19. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_models.py +46 -1
  20. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_submit.py +1 -1
  21. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/LICENSE +0 -0
  22. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/advent_of_code_data.egg-info/dependency_links.txt +0 -0
  23. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/advent_of_code_data.egg-info/entry_points.txt +0 -0
  24. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/advent_of_code_data.egg-info/top_level.txt +0 -0
  25. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/aocd/exceptions.py +0 -0
  26. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/setup.cfg +0 -0
  27. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_aocd.py +0 -0
  28. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_auth.py +0 -0
  29. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_cli.py +0 -0
  30. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_cookies.py +0 -0
  31. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_date_finding.py +0 -0
  32. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_date_introspection.py +0 -0
  33. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_example_parser.py +0 -0
  34. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_get_data.py +0 -0
  35. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_runner.py +0 -0
  36. {advent-of-code-data-2.0.0 → advent_of_code_data-2.0.2}/tests/test_utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: advent-of-code-data
3
- Version: 2.0.0
3
+ Version: 2.0.2
4
4
  Summary: Get your puzzle data with a single import
5
5
  Author-email: Wim Glenn <hey@wimglenn.com>
6
6
  License: MIT
@@ -12,8 +12,15 @@ Classifier: Topic :: Software Development :: Libraries
12
12
  Classifier: Topic :: Games/Entertainment :: Puzzle Games
13
13
  Requires-Python: >=3.9
14
14
  Description-Content-Type: text/x-rst
15
- Provides-Extra: nb
16
15
  License-File: LICENSE
16
+ Requires-Dist: beautifulsoup4
17
+ Requires-Dist: pebble
18
+ Requires-Dist: urllib3
19
+ Requires-Dist: tzdata; platform_system == "Windows"
20
+ Requires-Dist: aocd-example-parser>=2023.2
21
+ Provides-Extra: nb
22
+ Requires-Dist: IPython; extra == "nb"
23
+ Requires-Dist: jupyter-server; extra == "nb"
17
24
 
18
25
  Advent of Code data
19
26
  ===================
@@ -105,8 +112,10 @@ If you want to use this within a Jupyter notebook, there are some extra deps:
105
112
 
106
113
  export AOC_SESSION=cafef00db01dfaceba5eba11deadbeef
107
114
 
108
- This is a cookie which is set when you login to AoC. You can find it with
109
- your browser inspector. If you're hacking on AoC at all you probably already
115
+ *Note:* Windows users should use ``set`` instead of ``export`` here.
116
+
117
+ The session ID is a cookie which is set when you login to AoC. You can find it
118
+ with your browser inspector. If you're hacking on AoC at all you probably already
110
119
  know these kind of tricks, but if you need help with that part then you can
111
120
  `look here <https://github.com/wimglenn/advent-of-code/issues/1>`_.
112
121
 
@@ -116,8 +125,8 @@ variable to some existing directory if you wish to use another location to store
116
125
 
117
126
  *New in version 0.9.0.* There's a utility script ``aocd-token`` which attempts to
118
127
  find session tokens from your browser's cookie storage. This feature is experimental
119
- and requires you to additionally install the package ``browser-cookie3``. Only Chrome
120
- and Firefox browsers are currently supported. On macOS, you may get an authentication
128
+ and requires you to additionally install the package ``browser-cookie3``. Only Chrome,
129
+ Firefox, and Edge browsers are currently supported. On macOS, you may get an authentication
121
130
  dialog requesting permission, since Python is attempting to read browser storage files.
122
131
  This is expected, the script *is* actually scraping those private files to access AoC
123
132
  session token(s).
@@ -88,8 +88,10 @@ If you want to use this within a Jupyter notebook, there are some extra deps:
88
88
 
89
89
  export AOC_SESSION=cafef00db01dfaceba5eba11deadbeef
90
90
 
91
- This is a cookie which is set when you login to AoC. You can find it with
92
- your browser inspector. If you're hacking on AoC at all you probably already
91
+ *Note:* Windows users should use ``set`` instead of ``export`` here.
92
+
93
+ The session ID is a cookie which is set when you login to AoC. You can find it
94
+ with your browser inspector. If you're hacking on AoC at all you probably already
93
95
  know these kind of tricks, but if you need help with that part then you can
94
96
  `look here <https://github.com/wimglenn/advent-of-code/issues/1>`_.
95
97
 
@@ -99,8 +101,8 @@ variable to some existing directory if you wish to use another location to store
99
101
 
100
102
  *New in version 0.9.0.* There's a utility script ``aocd-token`` which attempts to
101
103
  find session tokens from your browser's cookie storage. This feature is experimental
102
- and requires you to additionally install the package ``browser-cookie3``. Only Chrome
103
- and Firefox browsers are currently supported. On macOS, you may get an authentication
104
+ and requires you to additionally install the package ``browser-cookie3``. Only Chrome,
105
+ Firefox, and Edge browsers are currently supported. On macOS, you may get an authentication
104
106
  dialog requesting permission, since Python is attempting to read browser storage files.
105
107
  This is expected, the script *is* actually scraping those private files to access AoC
106
108
  session token(s).
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: advent-of-code-data
3
- Version: 2.0.0
3
+ Version: 2.0.2
4
4
  Summary: Get your puzzle data with a single import
5
5
  Author-email: Wim Glenn <hey@wimglenn.com>
6
6
  License: MIT
@@ -12,8 +12,15 @@ Classifier: Topic :: Software Development :: Libraries
12
12
  Classifier: Topic :: Games/Entertainment :: Puzzle Games
13
13
  Requires-Python: >=3.9
14
14
  Description-Content-Type: text/x-rst
15
- Provides-Extra: nb
16
15
  License-File: LICENSE
16
+ Requires-Dist: beautifulsoup4
17
+ Requires-Dist: pebble
18
+ Requires-Dist: urllib3
19
+ Requires-Dist: tzdata; platform_system == "Windows"
20
+ Requires-Dist: aocd-example-parser>=2023.2
21
+ Provides-Extra: nb
22
+ Requires-Dist: IPython; extra == "nb"
23
+ Requires-Dist: jupyter-server; extra == "nb"
17
24
 
18
25
  Advent of Code data
19
26
  ===================
@@ -105,8 +112,10 @@ If you want to use this within a Jupyter notebook, there are some extra deps:
105
112
 
106
113
  export AOC_SESSION=cafef00db01dfaceba5eba11deadbeef
107
114
 
108
- This is a cookie which is set when you login to AoC. You can find it with
109
- your browser inspector. If you're hacking on AoC at all you probably already
115
+ *Note:* Windows users should use ``set`` instead of ``export`` here.
116
+
117
+ The session ID is a cookie which is set when you login to AoC. You can find it
118
+ with your browser inspector. If you're hacking on AoC at all you probably already
110
119
  know these kind of tricks, but if you need help with that part then you can
111
120
  `look here <https://github.com/wimglenn/advent-of-code/issues/1>`_.
112
121
 
@@ -116,8 +125,8 @@ variable to some existing directory if you wish to use another location to store
116
125
 
117
126
  *New in version 0.9.0.* There's a utility script ``aocd-token`` which attempts to
118
127
  find session tokens from your browser's cookie storage. This feature is experimental
119
- and requires you to additionally install the package ``browser-cookie3``. Only Chrome
120
- and Firefox browsers are currently supported. On macOS, you may get an authentication
128
+ and requires you to additionally install the package ``browser-cookie3``. Only Chrome,
129
+ Firefox, and Edge browsers are currently supported. On macOS, you may get an authentication
121
130
  dialog requesting permission, since Python is attempting to read browser storage files.
122
131
  This is expected, the script *is* actually scraping those private files to access AoC
123
132
  session token(s).
@@ -16,7 +16,9 @@ aocd/exceptions.py
16
16
  aocd/get.py
17
17
  aocd/models.py
18
18
  aocd/post.py
19
+ aocd/py.typed
19
20
  aocd/runner.py
21
+ aocd/types.py
20
22
  aocd/utils.py
21
23
  tests/test_aocd.py
22
24
  tests/test_auth.py
@@ -1,7 +1,7 @@
1
1
  beautifulsoup4
2
2
  pebble
3
3
  urllib3
4
- aocd-example-parser>=2023.1
4
+ aocd-example-parser>=2023.2
5
5
 
6
6
  [:platform_system == "Windows"]
7
7
  tzdata
@@ -1,4 +1,5 @@
1
1
  import sys
2
+ import typing as t
2
3
  from functools import partial
3
4
 
4
5
  from . import _ipykernel
@@ -10,14 +11,36 @@ from . import get
10
11
  from . import models
11
12
  from . import post
12
13
  from . import runner
14
+ from . import types
13
15
  from . import utils
14
16
  from .exceptions import AocdError
15
17
  from .get import get_data
16
18
  from .get import get_day_and_year
17
19
  from .post import submit as _impartial_submit
18
20
 
21
+ __all__ = [
22
+ "AocdError",
23
+ "cli",
24
+ "cookies",
25
+ "data",
26
+ "examples",
27
+ "exceptions",
28
+ "get",
29
+ "get_data",
30
+ "models",
31
+ "post",
32
+ "runner",
33
+ "submit",
34
+ "types",
35
+ "utils",
36
+ ]
19
37
 
20
- def __getattr__(name):
38
+ if t.TYPE_CHECKING:
39
+ data: str
40
+ submit = _impartial_submit
41
+
42
+
43
+ def __getattr__(name: str) -> t.Any:
21
44
  if name == "data":
22
45
  day, year = get_day_and_year()
23
46
  return get_data(day=day, year=year)
@@ -17,7 +17,8 @@ def get_ipynb_path():
17
17
  for serv in serverapp.list_running_servers():
18
18
  url = url_path_join(serv["url"], "api/sessions")
19
19
  resp = http.request("GET", url, fields={"token": serv["token"]})
20
- resp.raise_for_status()
20
+ if resp.status >= 400:
21
+ raise urllib3.exceptions.ResponseError(f"HTTP {resp.status}")
21
22
  for sess in resp.json():
22
23
  if kernel_id == sess["kernel"]["id"]:
23
24
  path = serv["root_dir"]
@@ -13,7 +13,7 @@ from .utils import AOC_TZ
13
13
  from .utils import get_plugins
14
14
 
15
15
 
16
- def main():
16
+ def main() -> None:
17
17
  """Get your puzzle input data, caching it if necessary, and print it on stdout."""
18
18
  aoc_now = datetime.datetime.now(tz=AOC_TZ)
19
19
  days = range(1, 26)
@@ -58,7 +58,7 @@ def main():
58
58
  "--example-parser",
59
59
  nargs="?",
60
60
  choices=plugins,
61
- const="aocd_examples_canned",
61
+ const="reference",
62
62
  help="get the example(s) data, if any",
63
63
  )
64
64
  if len(users) > 1:
@@ -12,10 +12,10 @@ from .utils import colored
12
12
  from .utils import get_owner
13
13
 
14
14
 
15
- log = logging.getLogger(__name__)
15
+ log: logging.Logger = logging.getLogger(__name__)
16
16
 
17
17
 
18
- def get_working_tokens():
18
+ def get_working_tokens() -> dict[str, str]:
19
19
  """Check browser cookie storage for session tokens from .adventofcode.com domain."""
20
20
  log.debug("checking for installation of browser-cookie3 package")
21
21
  try:
@@ -48,9 +48,20 @@ def get_working_tokens():
48
48
  firefox = [c for c in firefox if c.name == "session"]
49
49
  log.info("%d candidates from firefox", len(firefox))
50
50
 
51
+ log.info("checking edge cookie jar...")
52
+ try:
53
+ edge = bc3.edge(domain_name=".adventofcode.com")
54
+ except Exception as err:
55
+ log.debug("Couldn't scrape edge - %s: %s", type(err), err)
56
+ edge = []
57
+ else:
58
+ edge = [c for c in edge if c.name == "session"]
59
+ log.info("%d candidates from edge", len(edge))
60
+
61
+ cookies = chrome + firefox + edge
51
62
  # order preserving de-dupe
52
- tokens = list({}.fromkeys([c.value for c in chrome + firefox]))
53
- removed = len(chrome + firefox) - len(tokens)
63
+ tokens = list({}.fromkeys([c.value for c in cookies if c.value is not None]))
64
+ removed = len(cookies) - len(tokens)
54
65
  if removed:
55
66
  log.info("Removed %d duplicate%s", removed, "s"[: removed - 1])
56
67
 
@@ -66,7 +77,7 @@ def get_working_tokens():
66
77
  return result
67
78
 
68
79
 
69
- def scrape_session_tokens():
80
+ def scrape_session_tokens() -> None:
70
81
  """Scrape AoC session tokens from your browser's cookie storage."""
71
82
  aocd_token_path = AOCD_CONFIG_DIR / "token"
72
83
  aocd_tokens_path = AOCD_CONFIG_DIR / "tokens.json"
@@ -1,7 +1,10 @@
1
+ from __future__ import annotations
2
+
1
3
  import argparse
2
4
  import logging
3
5
  import re
4
6
  import sys
7
+ import typing as t
5
8
  from dataclasses import dataclass
6
9
  from datetime import datetime
7
10
  from itertools import zip_longest
@@ -16,7 +19,11 @@ from aocd.utils import AOC_TZ
16
19
  from aocd.utils import get_plugins
17
20
 
18
21
 
19
- log = logging.getLogger(__name__)
22
+ log: logging.Logger = logging.getLogger(__name__)
23
+
24
+ _AnswerElem = t.Literal[
25
+ "a_code", "a_li", "a_pre", "a_em", "b_code", "b_li", "b_pre", "b_em"
26
+ ]
20
27
 
21
28
 
22
29
  @dataclass
@@ -34,17 +41,17 @@ class Page:
34
41
  soup: bs4.BeautifulSoup # The raw_html string parsed into a bs4.BeautifulSoup instance
35
42
  year: int # AoC puzzle year (2015+) parsed from html title
36
43
  day: int # AoC puzzle day (1-25) parsed from html title
37
- article_a: bs4.element.Tag # The bs4 tag for the first <article> in the page, i.e. part a
38
- article_b: bs4.element.Tag # The bs4 tag for the second <article> in the page, i.e. part b. It will be `None` if part b locked
44
+ article_a: bs4.Tag # The bs4 tag for the first <article> in the page, i.e. part a
45
+ article_b: bs4.Tag | None # The bs4 tag for the second <article> in the page, i.e. part b. It will be `None` if part b locked
39
46
  a_raw: str # The first <article> html as a string
40
- b_raw: str # The second <article> html as a string. Will be `None` if part b locked
47
+ b_raw: str | None # The second <article> html as a string. Will be `None` if part b locked
41
48
 
42
- def __repr__(self):
49
+ def __repr__(self) -> str:
43
50
  part_a_only = "*" if self.article_b is None else ""
44
51
  return f"<Page({self.year}, {self.day}){part_a_only} at {hex(id(self))}>"
45
52
 
46
53
  @classmethod
47
- def from_raw(cls, html):
54
+ def from_raw(cls, html: str) -> Page:
48
55
  soup = _get_soup(html)
49
56
  title_pat = r"^Day (\d{1,2}) - Advent of Code (\d{4})$"
50
57
  title_text = soup.title.text
@@ -77,7 +84,7 @@ class Page:
77
84
  )
78
85
  return page
79
86
 
80
- def __getattr__(self, name):
87
+ def __getattr__(self, name: _AnswerElem) -> t.Sequence[str]:
81
88
  if not name.startswith(("a_", "b_")):
82
89
  raise AttributeError(name)
83
90
  part, sep, tag = name.partition("_")
@@ -118,12 +125,12 @@ class Example(NamedTuple):
118
125
  """
119
126
 
120
127
  input_data: str
121
- answer_a: str = None
122
- answer_b: str = None
123
- extra: str = None
128
+ answer_a: str | None = None
129
+ answer_b: str | None = None
130
+ extra: str | None = None
124
131
 
125
132
  @property
126
- def answers(self):
133
+ def answers(self) -> tuple[str | None, str | None]:
127
134
  return self.answer_a, self.answer_b
128
135
 
129
136
 
@@ -144,10 +151,10 @@ def _get_unique_real_inputs(year, day):
144
151
  return list({}.fromkeys(strs))
145
152
 
146
153
 
147
- def main():
154
+ def main() -> None:
148
155
  """
149
156
  Summarize an example parser's results with historical puzzles' prose, and
150
- compare the performance against a reference implementation (aocd_examples_canned)
157
+ compare the performance against a reference implementation
151
158
  """
152
159
  try:
153
160
  from rich.console import Console
@@ -166,12 +173,13 @@ def main():
166
173
  "-e",
167
174
  "--example-parser",
168
175
  choices=list(plugins),
169
- default="aocd_examples_canned",
176
+ default="reference",
170
177
  help="plugin to use for example extraction testing (default: %(default)s)",
171
178
  )
172
179
  parser.add_argument(
173
180
  "-y",
174
181
  "--years",
182
+ metavar="2015+",
175
183
  nargs="+",
176
184
  help="years to run the parser against (can specify multiple)",
177
185
  choices=all_years,
@@ -1,8 +1,12 @@
1
+ from __future__ import annotations
2
+
1
3
  import datetime
2
4
  import os
3
5
  import re
4
6
  import traceback
7
+ import typing as t
5
8
  from logging import getLogger
9
+ from logging import Logger
6
10
 
7
11
  from ._ipykernel import get_ipynb_path
8
12
  from .exceptions import AocdError
@@ -14,10 +18,15 @@ from .utils import AOC_TZ
14
18
  from .utils import blocker
15
19
 
16
20
 
17
- log = getLogger(__name__)
21
+ log: Logger = getLogger(__name__)
18
22
 
19
23
 
20
- def get_data(session=None, day=None, year=None, block=False):
24
+ def get_data(
25
+ session: str | None = None,
26
+ day: int | None = None,
27
+ year: int | None = None,
28
+ block: bool = False,
29
+ ) -> str:
21
30
  """
22
31
  Get data for day (1-25) and year (2015+).
23
32
  User's session cookie (str) is needed - puzzle inputs differ by user.
@@ -45,7 +54,7 @@ def get_data(session=None, day=None, year=None, block=False):
45
54
  return puzzle.input_data
46
55
 
47
56
 
48
- def most_recent_year():
57
+ def most_recent_year() -> int:
49
58
  """
50
59
  This year, if it's December.
51
60
  The most recent year, otherwise.
@@ -60,7 +69,7 @@ def most_recent_year():
60
69
  return year
61
70
 
62
71
 
63
- def current_day():
72
+ def current_day() -> int:
64
73
  """
65
74
  Most recent day, if it's during the Advent of Code. Happy Holidays!
66
75
  Day 1 is assumed, otherwise.
@@ -73,7 +82,7 @@ def current_day():
73
82
  return day
74
83
 
75
84
 
76
- def get_day_and_year():
85
+ def get_day_and_year() -> tuple[int, int | None]:
77
86
  """
78
87
  Returns tuple (day, year).
79
88