Skip to content

Commit 87b65ba

Browse files
authored
Merge pull request #86 from wimglenn/issue85
User.get_stats() works even if no stars collected yet. closes #85
2 parents 7007017 + 7eb305a commit 87b65ba

File tree

3 files changed

+13
-2
lines changed

3 files changed

+13
-2
lines changed

aocd/models.py

+2
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ def get_stats(self, years=None):
110110
response = requests.get(url, cookies=self.auth, headers=USER_AGENT)
111111
response.raise_for_status()
112112
soup = bs4.BeautifulSoup(response.text, "html.parser")
113+
if soup.article is None and "You haven't collected any stars" in soup.main.text:
114+
continue
113115
if soup.article.pre is None and "overall leaderboard" in soup.article.text:
114116
msg = "the auth token ...{} is expired or not functioning"
115117
raise DeadTokenError(msg.format(self.token[-4:]))

aocd/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.2.0"
1+
__version__ = "1.2.1"

tests/test_models.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,22 @@ def test_get_stats_when_token_expired(requests_mock):
228228
user = User("token12345678")
229229
requests_mock.get(
230230
url="https://adventofcode.com/2019/leaderboard/self",
231-
text="<article><p>Below is the <em>Advent of Code 2021</em> overall leaderboard</p></article>"
231+
text="<article><p>Below is the <em>Advent of Code 2019</em> overall leaderboard</p></article>"
232232
)
233233
expected_msg = "the auth token ...5678 is expired or not functioning"
234234
with pytest.raises(DeadTokenError(expected_msg)):
235235
user.get_stats(years=[2019])
236236

237237

238+
def test_get_stats_when_no_stars_yet(requests_mock):
239+
user = User("token12345678")
240+
requests_mock.get(
241+
url="https://adventofcode.com/2019/leaderboard/self",
242+
text="<main>You haven't collected any stars... yet.</main>"
243+
)
244+
assert user.get_stats(years=[2019]) == {}
245+
246+
238247
def test_get_stats_slow_user(requests_mock):
239248
puzzle = Puzzle(year=2019, day=25)
240249
requests_mock.get(

0 commit comments

Comments
 (0)