Skip to content

Commit

Permalink
fix: 404 on Mastodon (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida authored Sep 7, 2021
1 parent 24d456e commit 8950f3d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/nefelibata/announcers/mastodon.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ def announce(self, post: Post) -> str:
return cast(str, toot["url"])

def collect(self, post: Post) -> List[Response]:
_logger.info(f"Collecting replies from Mastodon ({self.base_url})")
_logger.info("Collecting replies from Mastodon (%s)", self.base_url)

toot_url = post.parsed[self.url_header]
toot_id = toot_url.rstrip("/").rsplit("/", 1)[1]
context = self.client.status_context(toot_id)
try:
context = self.client.status_context(toot_id)
except mastodon.MastodonNotFoundError:
_logger.warning("Toot not found: %s", toot_url)
return []

responses = []
for toot in context["descendants"]:
Expand Down
9 changes: 6 additions & 3 deletions tests/announcers/test_fawm.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ def test_get_comments_from_fawm_page(requests_mock):
html = fp.read()
requests_mock.get(url, text=html)

comments = get_comments_from_fawm_page(url, "username", "password")
with freeze_time("2020-12-01T00:00:00Z"):
comments = get_comments_from_fawm_page(url, "username", "password")

assert comments == [
{
Expand Down Expand Up @@ -258,7 +259,8 @@ def test_get_response_from_li():
features="html5lib",
)
el = soup.html.body.li
response = get_response_from_li(url, el)
with freeze_time("2020-12-01T00:00:00Z"):
response = get_response_from_li(url, el)

assert response == {
"source": "FAWM",
Expand Down Expand Up @@ -476,7 +478,8 @@ def test_announcer_extra_comments(mock_post, mocker, requests_mock):
post.parsed["fawm-url"] = "https://fawm.org/songs/1"
post.parsed["fawm-extra-url"] = "https://fawm.org/songs/2"

responses = announcer.collect(post)
with freeze_time("2020-12-01T00:00:00Z"):
responses = announcer.collect(post)
assert responses == [
{
"source": "FAWM",
Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_get_config_no_profile_picture(fs):
"author": {
"name": "Beto Dealmeida",
"email": "[email protected]",
"profile_picture": "http://www.gravatar.com/avatar/58b573d3eac03131faee739dfc7b360a",
"profile_picture": "https://www.gravatar.com/avatar/58b573d3eac03131faee739dfc7b360a",
},
"url": "http://blog.taoetc.org/",
"posts-to-show": 5,
Expand Down

0 comments on commit 8950f3d

Please sign in to comment.