Skip to content

Commit

Permalink
add README and minor refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
wimglenn committed Nov 20, 2024
1 parent 790e599 commit 44db6c0
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 6 additions & 23 deletions aocd/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import os
import re
import traceback
import typing as t
from logging import getLogger
from logging import Logger

Expand Down Expand Up @@ -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(
Expand All @@ -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()
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 44db6c0

Please sign in to comment.