summaryrefslogtreecommitdiff
path: root/aurweb/scripts/popupdate.py
diff options
context:
space:
mode:
authorLukas Fleischer <lfleischer@archlinux.org>2016-10-17 15:34:21 +0200
committerLukas Fleischer <lfleischer@archlinux.org>2016-10-17 15:34:21 +0200
commitfdd932ff8d5e5899cfeae9a8b29011fa2cf9d439 (patch)
tree07afb8664e18e4d4fb479525b16db6edf026b72b /aurweb/scripts/popupdate.py
parentb091fb77580d56dbdca6424f9065581945b8e815 (diff)
parentc3f464f50fb35ffb7825b90437bd912051a994ee (diff)
Merge branch 'master' into maintaurweb/maint
Diffstat (limited to 'aurweb/scripts/popupdate.py')
-rwxr-xr-xaurweb/scripts/popupdate.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/aurweb/scripts/popupdate.py b/aurweb/scripts/popupdate.py
new file mode 100755
index 0000000..58cd018
--- /dev/null
+++ b/aurweb/scripts/popupdate.py
@@ -0,0 +1,26 @@
+#!/usr/bin/python3
+
+import time
+
+import aurweb.db
+
+
+def main():
+ conn = aurweb.db.Connection()
+
+ conn.execute("UPDATE PackageBases SET NumVotes = (" +
+ "SELECT COUNT(*) FROM PackageVotes " +
+ "WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
+
+ now = int(time.time())
+ conn.execute("UPDATE PackageBases SET Popularity = (" +
+ "SELECT COALESCE(SUM(POWER(0.98, (? - VoteTS) / 86400)), 0.0) " +
+ "FROM PackageVotes WHERE PackageVotes.PackageBaseID = " +
+ "PackageBases.ID AND NOT VoteTS IS NULL)", [now])
+
+ conn.commit()
+ conn.close()
+
+
+if __name__ == '__main__':
+ main()