zhdo.space/helper.py

32 lines
753 B
Python
Raw Permalink Normal View History

2022-05-14 11:33:20 +08:00
import requests as python_requests
discussionPrefix = "https://talk.zhdo.space/topic/"
2022-05-13 22:11:11 +08:00
def getRecentArticle():
# TODO fetch latest article
recent = {"title": "N/A", "link": "#"}
return recent
2022-05-14 11:33:20 +08:00
2022-05-13 22:11:11 +08:00
def getRecentDiscussion():
recent = {"title": "N/A", "link": "#"}
2022-05-14 11:33:20 +08:00
obj = python_requests.get("https://talk.zhdo.space/api/recent/posts/week")
if obj.status_code == 200:
2022-05-14 12:11:36 +08:00
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
2022-05-14 11:33:20 +08:00
else:
return "error"
def main():
print(getRecentDiscussion())
if __name__ == "__main__":
main()