aurweb/scripts/popupdate.py
Lukas Fleischer 8c99184f6d Use config and db in scripts
Instead of using configparser and mysql.connector directly, change all
Python scripts to use the config and db Python modules which are now
accessible from a common location.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
2016-09-29 22:07:23 +02:00

23 lines
642 B
Python
Executable file

#!/usr/bin/python3
import aurweb.db
def main():
conn = aurweb.db.Connection()
conn.execute("UPDATE PackageBases SET NumVotes = (" +
"SELECT COUNT(*) FROM PackageVotes " +
"WHERE PackageVotes.PackageBaseID = PackageBases.ID)")
conn.execute("UPDATE PackageBases SET Popularity = (" +
"SELECT COALESCE(SUM(POWER(0.98, (UNIX_TIMESTAMP() - VoteTS) / 86400)), 0.0) " +
"FROM PackageVotes WHERE PackageVotes.PackageBaseID = " +
"PackageBases.ID AND NOT VoteTS IS NULL)")
conn.commit()
conn.close()
if __name__ == '__main__':
main()