diff backend/arangodb/Feed.py @ 256:f79be01821c4

Arangodb backend, first version which barely works for reading
author Dirk Olmes <dirk@xanthippe.ping.de>
date Wed, 30 Jan 2019 07:11:10 +0100
parents
children 304917762618
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/backend/arangodb/Feed.py	Wed Jan 30 07:11:10 2019 +0100
@@ -0,0 +1,32 @@
+# -*- coding: utf-8 -*-
+
+from datetime import datetime
+
+class Feed(object):
+    def __init__(self, document):
+        super(Feed, self).__init__()
+        self.document = document
+
+    def __getattr__(self, attribute):
+        return self.document[attribute]
+
+    @staticmethod
+    def get_unread(database):
+        query = """ 
+            FOR feed_entry_doc IN feed_entry
+                FOR feed_doc IN feed
+                    FILTER feed_entry_doc.read == false
+                    AND feed_entry_doc.feed == feed_doc._key
+                    RETURN DISTINCT feed_doc"""
+        results = database.AQLQuery(query)
+        return [Feed(doc) for doc in results]
+
+    @staticmethod
+    def all_pending_update(database):
+        query = """
+        FOR feed_doc IN feed
+            FILTER DATE_ISO8601(DATE_NOW()) > feed_doc.next_update
+            RETURN feed_doc
+        """
+        results = database.AQLQuery(query)
+        return [Feed(doc) for doc in results]