diff options
Diffstat (limited to 'pyaggr3g470r/controllers/feed.py')
-rw-r--r-- | pyaggr3g470r/controllers/feed.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/pyaggr3g470r/controllers/feed.py b/pyaggr3g470r/controllers/feed.py new file mode 100644 index 00000000..a2455e2b --- /dev/null +++ b/pyaggr3g470r/controllers/feed.py @@ -0,0 +1,24 @@ +from datetime import datetime, timedelta +from .abstract import AbstractController +from pyaggr3g470r.models import Feed + +DEFAULT_MAX_ERROR = 3 +DEFAULT_LIMIT = 5 + + +class FeedController(AbstractController): + _db_cls = Feed + + def list_fetchable(self, max_error=DEFAULT_MAX_ERROR, limit=DEFAULT_LIMIT): + from pyaggr3g470r.controllers import UserController + now = datetime.now() + user = UserController(self.user_id).get(id=self.user_id) + max_last = now - timedelta(minutes=user.refresh_rate or 60) + feeds = [feed for feed in self.read(user_id=self.user_id, + error_count__lt=max_error, enabled=True, + last_retreived__lt=max_last).limit(limit)] + + if feeds: + self.update({'id__in': [feed.id for feed in feeds]}, + {'last_retreived': now}) + return feeds |