krz/daily-poem

Archived

Poetry emailed, at your will. automation email poetry

Commit cf07c80186

cf07c8018696cf3dde671cedc0d5ba6f50050524

parent: c63697469a

Verified · cmc

cmc <hello@cleberg.net> · 2026-11-01 05:46 UTC

Check HTTP status before parsing PoetryDB response

Ref #2

Layout: unified · split

main.py +3 −1
@@ -22,7 +22,9 @@ class Poem(NamedTuple):
2222
2323def fetch_poem(url=POETRY_URL):
2424 """Return a random poem."""
25 json_data = requests.get(url, timeout=30).json()
25 resp = requests.get(url, timeout=30)
26 resp.raise_for_status()
27 json_data = resp.json()
2628 poem = json_data[0]
2729 lines = ""
2830 for line in poem["lines"]:
tests/test_main.py +3
@@ -8,6 +8,9 @@ class FakeResponse:
88 def __init__(self, payload):
99 self._payload = payload
1010
11 def raise_for_status(self):
12 pass
13
1114 def json(self):
1215 return self._payload
1316