Mercurial > hg > Feedworm
view 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 |
line wrap: on
line source
# -*- coding: utf-8 -*- from datetime import datetime, timedelta class Feed(object): @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] def __init__(self, document): super(Feed, self).__init__() self.document = document def __getattr__(self, attribute): return self.document[attribute] def increment_next_update_date(self): updateInterval = self._updateIntervalInSeconds() delta = timedelta(seconds=updateInterval) next_update = datetime.now() + delta self.document['next_update'] = next_update.strftime('%Y-%m-%dT%H:%M:%S.000') self.document.patch() def _updateIntervalInSeconds(self): return self.update_interval * 60