From 988c90ce774d163a5aec17e18fd9c9c3c8bfb3b0 Mon Sep 17 00:00:00 2001 From: jwansek Date: Sun, 12 Feb 2023 21:34:35 +0000 Subject: Added exception handling for when a github repo is empty --- database.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'database.py') diff --git a/database.py b/database.py index cf51922..c8bf5ff 100755 --- a/database.py +++ b/database.py @@ -339,23 +339,28 @@ def request_recent_commits(since = datetime.datetime.now() - datetime.timedelta( out = [] for repo in g.get_user().get_repos(): # print(repo.name, list(repo.get_branches())) - for commit in repo.get_commits(since = since): - out.append({ - "repo": repo.name, - "message": commit.commit.message, - "url": commit.html_url, - "datetime": commit.commit.author.date, - "stats": { - "additions": commit.stats.additions, - "deletions": commit.stats.deletions, - "total": commit.stats.total - } - }) + try: + for commit in repo.get_commits(since = since): + out.append({ + "repo": repo.name, + "message": commit.commit.message, + "url": commit.html_url, + "datetime": commit.commit.author.date, + "stats": { + "additions": commit.stats.additions, + "deletions": commit.stats.deletions, + "total": commit.stats.total + } + }) + except Exception as e: + print(e) + return sorted(out, key = lambda a: a["datetime"], reverse = True) if __name__ == "__main__": - import app - with Database() as db: - print(app.get_sidebar_img(db)) - # print(db.get_sidebar_images()) + print(request_recent_commits()) + #import app + #with Database() as db: + # print(app.get_sidebar_img(db)) + # # print(db.get_sidebar_images()) -- cgit v1.2.3 From 7c53f89ccdd92e308d14d069e2e070f7a1c2da26 Mon Sep 17 00:00:00 2001 From: jwansek Date: Mon, 27 Feb 2023 00:05:41 +0000 Subject: Added q&a page --- database.py | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'database.py') diff --git a/database.py b/database.py index c8bf5ff..8829615 100755 --- a/database.py +++ b/database.py @@ -3,7 +3,9 @@ from dataclasses import dataclass from github import Github from lxml import html import configparser +import curiouscat import threading +import operator import datetime import requests import twython @@ -304,9 +306,45 @@ class Database: self.__connection.commit() + def get_curiouscat_username(self): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT link FROM headerLinks WHERE name = 'curiouscat';") + return urlparse(cursor.fetchone()[0]).path.split("/")[1] + + def append_curiouscat_qnas(self, qnas): + with self.__connection.cursor() as cursor: + for qna in qnas: + cursor.execute("SELECT curiouscat_id FROM qnas WHERE curiouscat_id = %s;", (qna["id"], )) + if cursor.fetchone() is None: + + cursor.execute("INSERT INTO `qnas` VALUES (%s, %s, %s, %s, %s);", ( + qna["id"], qna["link"], qna["datetime"], qna["question"], qna["answer"] + )) + print("Appended question with timestamp %s" % datetime.datetime.fromtimestamp(qna["id"]).isoformat()) + + else: + print("Skipped question with timestamp %s" % datetime.datetime.fromtimestamp(qna["id"]).isoformat()) + self.__connection.commit() + + def get_biggest_curiouscat_timestamp(self): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT MAX(`timestamp`) FROM `qnas`;") + return cursor.fetchone()[0] + + def get_curiouscat_qnas(self): + with self.__connection.cursor() as cursor: + cursor.execute("SELECT * FROM qnas;") + return sorted(cursor.fetchall(), key = operator.itemgetter(2), reverse = True) + def update_cache(): # print("updating cache...") with Database() as db: + db.append_curiouscat_qnas( + curiouscat.get_all_curiouscat_qnas_before( + db.get_curiouscat_username(), + db.get_biggest_curiouscat_timestamp() + ) + ) db.fetch_diary() db.update_twitter_cache(request_recent_tweets(10000)) # print("Done updating twitter cache...") @@ -359,8 +397,6 @@ def request_recent_commits(since = datetime.datetime.now() - datetime.timedelta( if __name__ == "__main__": - print(request_recent_commits()) - #import app - #with Database() as db: - # print(app.get_sidebar_img(db)) - # # print(db.get_sidebar_images()) + # print(request_recent_commits()) + with Database() as db: + print(db.get_curiouscat_qnas()) -- cgit v1.2.3 From 966fe80c956fec5dd2fb3ee27b488a8e1453eafa Mon Sep 17 00:00:00 2001 From: jwansek Date: Thu, 2 Mar 2023 16:44:41 +0000 Subject: Updated fetching for the diary page, attempting to ignore automatic curiouscat tweets buy comparing the first 16 characters with the curiouscat table --- database.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'database.py') diff --git a/database.py b/database.py index 8829615..1a02cea 100755 --- a/database.py +++ b/database.py @@ -227,7 +227,9 @@ class Database: threading.Thread(target = update_cache).start() out = {} with self.__connection.cursor() as cursor: - cursor.execute("SELECT tweet_id, tweeted_at, tweet FROM diary WHERE replying_to IS NULL ORDER BY tweeted_at DESC;") + # cursor.execute("SELECT tweet_id, tweeted_at, tweet FROM diary WHERE replying_to IS NULL ORDER BY tweeted_at DESC;") + # attempt to ignore curiouscat automatic tweets by comparing with the q&a table + cursor.execute("SELECT tweet_id, tweeted_at, tweet FROM diary WHERE replying_to IS NULL AND tweet_id NOT IN (SELECT tweet_id FROM diary INNER JOIN qnas ON SUBSTRING(tweet, 1, 16) = SUBSTRING(question, 1, 16)) ORDER BY tweeted_at DESC;") for tweet_id, tweeted_at, tweet_text in cursor.fetchall(): # print(tweet_id, tweeted_at, tweet_text) out[tweeted_at] = [{ -- cgit v1.2.3