comparison backend/arangodb/Feed.py @ 259:304917762618 default tip

implementation of feed updates
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 12 Mar 2019 02:41:22 +0100
parents f79be01821c4
children
comparison
equal deleted inserted replaced
258:4ca1fac32dde 259:304917762618
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 from datetime import datetime 3 from datetime import datetime, timedelta
4 4
5 class Feed(object): 5 class Feed(object):
6 def __init__(self, document):
7 super(Feed, self).__init__()
8 self.document = document
9
10 def __getattr__(self, attribute):
11 return self.document[attribute]
12
13 @staticmethod 6 @staticmethod
14 def get_unread(database): 7 def get_unread(database):
15 query = """ 8 query = """
16 FOR feed_entry_doc IN feed_entry 9 FOR feed_entry_doc IN feed_entry
17 FOR feed_doc IN feed 10 FOR feed_doc IN feed
28 FILTER DATE_ISO8601(DATE_NOW()) > feed_doc.next_update 21 FILTER DATE_ISO8601(DATE_NOW()) > feed_doc.next_update
29 RETURN feed_doc 22 RETURN feed_doc
30 """ 23 """
31 results = database.AQLQuery(query) 24 results = database.AQLQuery(query)
32 return [Feed(doc) for doc in results] 25 return [Feed(doc) for doc in results]
26
27 def __init__(self, document):
28 super(Feed, self).__init__()
29 self.document = document
30
31 def __getattr__(self, attribute):
32 return self.document[attribute]
33
34 def increment_next_update_date(self):
35 updateInterval = self._updateIntervalInSeconds()
36 delta = timedelta(seconds=updateInterval)
37 next_update = datetime.now() + delta
38 self.document['next_update'] = next_update.strftime('%Y-%m-%dT%H:%M:%S.000')
39 self.document.patch()
40
41 def _updateIntervalInSeconds(self):
42 return self.update_interval * 60