diff options
author | jwansek <eddie.atten.ea29@gmail.com> | 2023-02-27 00:05:41 +0000 |
---|---|---|
committer | jwansek <eddie.atten.ea29@gmail.com> | 2023-02-27 00:05:41 +0000 |
commit | 7c53f89ccdd92e308d14d069e2e070f7a1c2da26 (patch) | |
tree | b16a2405e88070abe29b909314cfbd5b3d21d2cf /curiouscat.py | |
parent | 2831eb8af07b1c387f17cf4d9a4b3a1b1aa47bb5 (diff) | |
download | eda.gay-7c53f89ccdd92e308d14d069e2e070f7a1c2da26.tar.gz eda.gay-7c53f89ccdd92e308d14d069e2e070f7a1c2da26.zip |
Added q&a page
Diffstat (limited to 'curiouscat.py')
-rw-r--r-- | curiouscat.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/curiouscat.py b/curiouscat.py new file mode 100644 index 0000000..90cdaf6 --- /dev/null +++ b/curiouscat.py @@ -0,0 +1,47 @@ +import datetime +import requests +import json + +def get_curiouscat_qnas_after(name, last_timestamp = None): + if last_timestamp is None: + url = "https://curiouscat.live/api/v2/profile?username=%s&count=100" % (name) + else: + url = "https://curiouscat.live/api/v2/profile?username=%s&count=100&max_timestamp=%d" % (name, last_timestamp) + + req = requests.get(url) + return req.json()["posts"] + +def get_all_curiouscat_qnas(name): + out = [] + period = get_curiouscat_qnas_after(name) + out += period + while len(period) == 100: + oldest = min([i["timestamp"] for i in period]) + period = get_curiouscat_qnas_after("jwnskanzkwk", last_timestamp = oldest - 1) + + out += period + + return post_process(out, name) + +def get_all_curiouscat_qnas_before(name, min_dt): + url = "https://curiouscat.live/api/v2/profile?username=%s&count=100&min_timestamp=%d" % (name, int(min_dt.timestamp()) + 1) + req = requests.get(url) + return post_process(req.json()["posts"], "name") + +def post_process(cc, name): + return [ + { + "id": i["id"], + "link": "https://curiouscat.me/%s/post/%d" % (name, i["id"]), + "datetime": datetime.datetime.fromtimestamp(i["timestamp"]), + "question": i["comment"], + "answer": i["reply"] + } + for i in cc + ] + +if __name__ == "__main__": + import database + + with database.Database() as db: + print(db.append_curiouscat_qnas(get_all_curiouscat_qnas_before("jwnskanzkwk", db.get_biggest_curiouscat_timestamp())))
\ No newline at end of file |