summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTianhao Wang <shrik3@riseup.net>2023-03-29 15:30:14 +0200
committerTianhao Wang <shrik3@riseup.net>2023-03-29 15:30:14 +0200
commita05d9ccfd06059aef9ebd2608f16fc0953cf5ab1 (patch)
treeeb28ad77d6ef2b18ce38ba70e42a8087cda29f3f
parent04c0fd709b868400a826bca05c679a8c4f1abb8d (diff)
count intimacy, untested
-rw-r--r--cat.py14
-rw-r--r--catdb.py13
-rw-r--r--catquery.py7
3 files changed, 33 insertions, 1 deletions
diff --git a/cat.py b/cat.py
index 544cbc7..75da443 100644
--- a/cat.py
+++ b/cat.py
@@ -50,6 +50,9 @@ class VnilCat:
print("[ERROR] failed to setup DB ...",e)
print("exit ...")
exit()
+ self.intimacy = {}
+ print("[booting] init intimacy")
+ self.update_intimacy()
# try to fetch the lastest status from the timeline
# so that we can skip the ones before we start.
@@ -66,6 +69,11 @@ class VnilCat:
print(f"[booting] Cat booted, all systems green, my name is {self.config.UNAME}, prepare to die, human")
print("-------------")
+ def update_intimacy():
+ res = self.db.count_interaction()
+ if res != None:
+ self.intimacy = res
+
def not_mine(self, status):
return status['account']['acct'] != self.config.UNAME
@@ -117,6 +125,10 @@ class VnilCat:
if actor not in self.config.ADMINS:
return
self.post_hn_news()
+ elif cmd[0] == "stats":
+ if actor not in self.config.ADMINS:
+ return
+ self.session.status_reply(to_status=status, status=str(self.intimacy))
else:
print("I don't understand")
@@ -199,7 +211,9 @@ class VnilCat:
self.handle_notification()
self.scantimeline()
if self.epoch % 360 == 1 :
+ # happens roughtly every 2 hours
self.post_hn_news(3)
+ self.update_intimacy()
except Exception as e:
print("something wrong...")
print(e)
diff --git a/catdb.py b/catdb.py
index 14843f8..e3bf921 100644
--- a/catdb.py
+++ b/catdb.py
@@ -29,7 +29,7 @@ class DBHandler():
def query(self,str):
conn = sqlite3.connect(self.DB)
cur = conn.cursor()
- res = cur.execute(str)
+ res = cur.execute(str).fetchall()
conn.close()
return res
@@ -42,3 +42,14 @@ class DBHandler():
except Exception as e:
print("ERROR ","failed to insert event to the db, ignoring ",e)
+ def count_interaction(self):
+ try:
+ res = self.query(QUERY_COUNT_INTERACTION)
+ return dict(res)
+ except:
+ print("query failed")
+ return None
+
+
+
+
diff --git a/catquery.py b/catquery.py
index 7b3bc5c..12921c4 100644
--- a/catquery.py
+++ b/catquery.py
@@ -14,3 +14,10 @@ QUERY_INSERT_EVENT = \
INSERT INTO events(type, remarks, correspond) VALUES (?,?,?)
"""
+
+QUERY_COUNT_INTERACTION = \
+"""
+SELECT correspond, count(correspond)
+ FROM events
+ GROUP by correspond
+"""