summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authordumpfmprod <dumpfmprod@ubuntu.(none)>2010-10-03 09:08:19 -0400
committerdumpfmprod <dumpfmprod@ubuntu.(none)>2010-10-03 09:08:19 -0400
commite5f01c9ad63b4547900a488c452523a3f88344c5 (patch)
tree3017ff555cc4e991b13b0913adacfe3f8a9c5c81 /scripts
parent3cf4af29bc9744f34aed362113dd6f158ec19144 (diff)
timb: testing using redis to store a sorted set of post favcounts
Diffstat (limited to 'scripts')
-rw-r--r--scripts/hiscores/.month.py.swpbin0 -> 12288 bytes
-rw-r--r--scripts/hiscores/day.py35
-rw-r--r--scripts/hiscores/month.py35
-rw-r--r--scripts/hiscores/week.py35
4 files changed, 105 insertions, 0 deletions
diff --git a/scripts/hiscores/.month.py.swp b/scripts/hiscores/.month.py.swp
new file mode 100644
index 0000000..4293f41
--- /dev/null
+++ b/scripts/hiscores/.month.py.swp
Binary files differ
diff --git a/scripts/hiscores/day.py b/scripts/hiscores/day.py
new file mode 100644
index 0000000..d59ecdf
--- /dev/null
+++ b/scripts/hiscores/day.py
@@ -0,0 +1,35 @@
+# 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()
diff --git a/scripts/hiscores/month.py b/scripts/hiscores/month.py
new file mode 100644
index 0000000..616cccc
--- /dev/null
+++ b/scripts/hiscores/month.py
@@ -0,0 +1,35 @@
+# 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()
diff --git a/scripts/hiscores/week.py b/scripts/hiscores/week.py
new file mode 100644
index 0000000..3853abd
--- /dev/null
+++ b/scripts/hiscores/week.py
@@ -0,0 +1,35 @@
+# 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 '7 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.week", message_id, 1)
+
+def rm_low_scores():
+ r.zremrangebyscore("hiscore.week", 0, 5)
+
+if __name__ == "__main__":
+ clear_redis()
+ favs = fetch_favs()
+ add_favs_to_redis(favs)
+ rm_low_scores()