[odrs-web/production] Add a utility to generate the semi-static data in a cron job
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [odrs-web/production] Add a utility to generate the semi-static data in a cron job
- Date: Fri, 25 May 2018 14:37:59 +0000 (UTC)
commit 4649012266b7cdce14d160f24d698547a87d18cf
Author: Richard Hughes <richard hughsie com>
Date: Fri May 25 15:37:26 2018 +0100
Add a utility to generate the semi-static data in a cron job
cron.py | 44 ++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 44 insertions(+), 0 deletions(-)
---
diff --git a/cron.py b/cron.py
new file mode 100755
index 0000000..8a189d6
--- /dev/null
+++ b/cron.py
@@ -0,0 +1,44 @@
+#!/usr/bin/python2
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2016-2018 Richard Hughes <richard hughsie com>
+# Licensed under the GNU General Public License Version 3
+
+import json
+import os
+import sys
+
+from app.db import Database
+
+if __name__ == '__main__':
+
+ if len(sys.argv) < 3:
+ print('Usage: %s ratings filename' % sys.argv[0])
+ sys.exit(1)
+
+ # create the ratings data
+ if sys.argv[1] == 'ratings':
+ item = {}
+ try:
+ db = Database(None)
+ app_ids = db.reviews.get_all_apps()
+ for app_id in app_ids:
+ ratings = db.reviews.get_rating_for_app_id(app_id, 2)
+ if len(ratings) == 0:
+ continue
+ item[app_id] = ratings
+ except CursorError as e:
+ print(str(e))
+ os.exit(1)
+
+ # dump to file
+ dat = json.dumps(item, sort_keys=True, indent=4, separators=(',', ': '))
+ outfd = open(sys.argv[2], "w")
+ outfd.write(dat)
+ outfd.close()
+ else:
+ print("cron mode %s not known" % sys.argv[1])
+ sys.exit(1)
+
+ # success
+ sys.exit(0)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]