annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
256
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 from datetime import datetime
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5 class Feed(object):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 def __init__(self, document):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7 super(Feed, self).__init__()
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 self.document = document
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 def __getattr__(self, attribute):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11 return self.document[attribute]
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
13 @staticmethod
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
14 def get_unread(database):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
15 query = """
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
16 FOR feed_entry_doc IN feed_entry
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
17 FOR feed_doc IN feed
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
18 FILTER feed_entry_doc.read == false
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
19 AND feed_entry_doc.feed == feed_doc._key
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
20 RETURN DISTINCT feed_doc"""
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
21 results = database.AQLQuery(query)
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
22 return [Feed(doc) for doc in results]
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
23
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
24 @staticmethod
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
25 def all_pending_update(database):
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
26 query = """
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
27 FOR feed_doc IN feed
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
28 FILTER DATE_ISO8601(DATE_NOW()) > feed_doc.next_update
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
29 RETURN feed_doc
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
30 """
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
31 results = database.AQLQuery(query)
f79be01821c4 Arangodb backend, first version which barely works for reading
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
32 return [Feed(doc) for doc in results]