summaryrefslogtreecommitdiff
path: root/scripts/hiscores/day.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/hiscores/day.py')
-rw-r--r--scripts/hiscores/day.py35
1 files changed, 0 insertions, 35 deletions
diff --git a/scripts/hiscores/day.py b/scripts/hiscores/day.py
deleted file mode 100644
index d59ecdf..0000000
--- a/scripts/hiscores/day.py
+++ /dev/null
@@ -1,35 +0,0 @@
-# this needs python 3
-
-import re
-import sys
-import postgresql
-from urllib.parse import urlparse
-import redis
-
-db = postgresql.open("pq://postgres:root@localhost/dumpfm")
-db.execute("SET CLIENT_ENCODING to 'UNICODE'")
-
-r = redis.Redis("localhost")
-
-def clear_redis():
- r.delete("hiscore.day")
-
-def fetch_favs():
- ps = db.prepare("SELECT user_id, message_id, created_on FROM tags WHERE created_on > (now() - INTERVAL '1 day') AND LOWER(tag) = 'favorite'")
- rows = ps()
- return rows
-
-def add_favs_to_redis(favs):
- for fav in favs:
- user_id = fav[0]
- message_id = fav[1]
- r.zincrby("hiscore.day", message_id, 1)
-
-def rm_low_scores():
- r.zremrangebyscore("hiscore.day", 0, 5)
-
-if __name__ == "__main__":
- clear_redis()
- favs = fetch_favs()
- add_favs_to_redis(favs)
- rm_low_scores()