Add error checking

This commit is contained in:
juan 2022-05-14 12:11:36 +08:00
parent 81d8f1f892
commit 135f8d0b65

View File

@ -13,6 +13,9 @@ def getRecentDiscussion():
recent = {"title": "N/A", "link": "#"}
obj = python_requests.get("https://talk.zhdo.space/api/recent/posts/week")
if obj.status_code == 200:
if not obj.json():
return recent
else:
recent["title"] = str(obj.json()[0]["topic"]["title"])
recent["link"] = discussionPrefix + str(obj.json()[0]["topic"]["slug"])
return recent