diff options
Diffstat (limited to 'scripts/hiscores/month.py')
| -rw-r--r-- | scripts/hiscores/month.py | 35 |
1 files changed, 0 insertions, 35 deletions
diff --git a/scripts/hiscores/month.py b/scripts/hiscores/month.py deleted file mode 100644 index 616cccc..0000000 --- a/scripts/hiscores/month.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 '30 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.month", message_id, 1) - -def rm_low_scores(): - r.zremrangebyscore("hiscore.month", 0, 5) - -if __name__ == "__main__": - clear_redis() - favs = fetch_favs() - add_favs_to_redis(favs) - rm_low_scores() |
