diff --git a/README.md b/README.md index c29c396..9fcd0d8 100644 --- a/README.md +++ b/README.md @@ -173,6 +173,9 @@ aocd will not submit that answer again. You've previously guessed 299 and the se That's not the right answer; your answer is too high. If you're stuck, there are some general tips on the about page, or you can ask for hints on the subreddit. Please wait one minute before trying again. (You guessed 299.) [Return to Day 20] ``` +*New in version 2.0.4:* Added convenience `from aocd import puzzle`, +to return a `Puzzle` instance bound to the auto-detected day/year/user. + Your own solutions can be executed by writing and using an [entry-point](https://packaging.python.org/specifications/entry-points/) into your code, registered in the group `"adventofcode.user"`. Your diff --git a/aocd/get.py b/aocd/get.py index fbc0ae9..9579096 100644 --- a/aocd/get.py +++ b/aocd/get.py @@ -4,7 +4,6 @@ import os import re import traceback -import typing as t from logging import getLogger from logging import Logger @@ -33,25 +32,8 @@ def get_data( If `block` is True and the puzzle is still locked, will wait until unlock before returning data. """ - if session is None: - user = default_user() - else: - user = User(token=session) - if day is None: - day = current_day() - log.info("current day=%s", day) - if year is None: - year = most_recent_year() - log.info("most recent year=%s", year) - puzzle = Puzzle(year=year, day=day, user=user) - try: - return puzzle.input_data - except PuzzleLockedError: - if not block: - raise - q = block == "q" - blocker(quiet=q, until=(year, day)) - return puzzle.input_data + puzzle = get_puzzle(session, day, year, block) + return puzzle.input_data def get_puzzle( @@ -64,7 +46,7 @@ def get_puzzle( Get puzzle for day (1-25) and year (2015+). User's session cookie (str) is needed - puzzle inputs differ by user. If `block` is True and the puzzle is still locked, will wait until unlock - before returning data. + before returning puzzle. """ if session is None: user = default_user() @@ -78,14 +60,15 @@ def get_puzzle( log.info("most recent year=%s", year) puzzle = Puzzle(year=year, day=day, user=user) try: - _ = puzzle.input_data - return puzzle + puzzle.input_data except PuzzleLockedError: if not block: raise q = block == "q" blocker(quiet=q, until=(year, day)) return puzzle + else: + return puzzle def most_recent_year() -> int: diff --git a/pyproject.toml b/pyproject.toml index 4440103..a0bda70 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta" [project] name = "advent-of-code-data" -version = "2.0.3" +version = "2.0.4" description = "Get your puzzle data with a single import" readme = "README.md" requires-python = ">=3.9"