Jelajahi Sumber

add error counting analytics

David 9 tahun lalu
induk
melakukan
aadccfecd8
2 mengubah file dengan 11 tambahan dan 0 penghapusan
  1. 7 0
      analytics.py
  2. 4 0
      db.py

+ 7 - 0
analytics.py

@@ -19,3 +19,10 @@ def post_data(field, keys, value):
             print(data, "failed!!")
     except Exception as e:
         pass
+
+
+if __name__ == '__main__':
+    from db import db
+    errors = db().get_sources_with_error()
+    for e in errors:
+        post_data('error', {'source': e['_id']}, e['count'])

+ 4 - 0
db.py

@@ -184,3 +184,7 @@ class db():
             print(res)
             self.c_articles.update({"_id": ObjectId(a["_id"])}, {"$set": res})
             #matches, kw, weight
+
+    def get_sources_with_error(self):
+        self.c_articles.aggregate([{'$match': {'error': True}},
+                                   {'$group': {'_id': '$source_name', 'count': {'$sum': 1}}}])