Skip to content

Commit 0305c8e

Browse files
authored
don't allow access to Puzzle.my_stats unless both parts have been solved (#16)
* don't allow access to Puzzle.my_stats unless both parts have been solved * oops
1 parent e3b2c81 commit 0305c8e

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

aocd/models.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,15 @@ def my_stats(self):
361361
soup = bs4.BeautifulSoup(response.text, "html.parser")
362362
stats_txt = soup.article.pre.text
363363
lines = stats_txt.splitlines()
364-
try:
365-
[line] = [x for x in lines if x.split()[0] == str(self.day)]
366-
except ValueError:
367-
log.debug("failed to parse stats\n%s", stats_txt)
364+
line = [x for x in lines if x.split()[0] == str(self.day)]
365+
if len(line) != 1:
366+
log.debug("failed to parse stats table\n%s", stats_txt)
368367
raise PuzzleUnsolvedError
368+
[line] = line
369369
vals = line.split()
370370
assert int(vals[0]) == self.day
371+
if vals[4] == "-":
372+
raise PuzzleUnsolvedError
371373
result = {
372374
"a": {
373375
"time": _parse_duration(vals[1]),

aocd/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "0.8.4"
1+
__version__ = "0.8.5"

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
setup(
55
name="advent-of-code-data",
6-
version="0.8.4",
6+
version="0.8.5",
77
description="Get your puzzle data with a single import",
88
long_description=open("README.rst").read(),
99
long_description_content_type="text/x-rst",

tests/test_models.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ def test_aocr_override(monkeypatch, tmp_path):
189189
Day <span class="leaderboard-daydesc-first"> Time Rank Score</span>
190190
<span class="leaderboard-daydesc-both"> Time Rank Score</span>
191191
25 >24h 2708 0 >24h 1926 0
192+
24 >24h 2708 0 - - -
192193
4 00:03:30 158 0 00:04:17 25 76
193194
3 00:24:44 729 0 00:36:00 710 0
194195
2 01:11:16 4087 0 01:23:27 3494 0
@@ -231,6 +232,15 @@ def test_get_stats_fail(requests_mock):
231232
puzzle.my_stats
232233

233234

235+
def test_get_stats_partial_fail(requests_mock):
236+
puzzle = Puzzle(year=2019, day=24)
237+
requests_mock.get(
238+
url="https://adventofcode.com/2019/leaderboard/self", text=fake_stats_response,
239+
)
240+
with pytest.raises(PuzzleUnsolvedError):
241+
puzzle.my_stats
242+
243+
234244
def test_puzzle_view(mocker):
235245
browser_open = mocker.patch("aocd.models.webbrowser.open")
236246
puzzle = Puzzle(year=2019, day=4)

0 commit comments

Comments
 (0)