Add error checking
This commit is contained in:
parent
81d8f1f892
commit
135f8d0b65
@ -13,9 +13,12 @@ def getRecentDiscussion():
|
|||||||
recent = {"title": "N/A", "link": "#"}
|
recent = {"title": "N/A", "link": "#"}
|
||||||
obj = python_requests.get("https://talk.zhdo.space/api/recent/posts/week")
|
obj = python_requests.get("https://talk.zhdo.space/api/recent/posts/week")
|
||||||
if obj.status_code == 200:
|
if obj.status_code == 200:
|
||||||
recent["title"] = str(obj.json()[0]["topic"]["title"])
|
if not obj.json():
|
||||||
recent["link"] = discussionPrefix + str(obj.json()[0]["topic"]["slug"])
|
return recent
|
||||||
return recent
|
else:
|
||||||
|
recent["title"] = str(obj.json()[0]["topic"]["title"])
|
||||||
|
recent["link"] = discussionPrefix + str(obj.json()[0]["topic"]["slug"])
|
||||||
|
return recent
|
||||||
else:
|
else:
|
||||||
return "error"
|
return "error"
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user