diff options
Diffstat (limited to 'pyaggr3g470r/controllers/feed.py')
-rw-r--r-- | pyaggr3g470r/controllers/feed.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/pyaggr3g470r/controllers/feed.py b/pyaggr3g470r/controllers/feed.py index 5ada1a48..ce1c413f 100644 --- a/pyaggr3g470r/controllers/feed.py +++ b/pyaggr3g470r/controllers/feed.py @@ -1,6 +1,23 @@ +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_refresh = now - timedelta(minutes=user.refresh_rate or 60) + feeds = [feed for feed in self.read(user_id=self.user_id, + error_count__le=max_error, + last_refreshed__lt=max_last_refresh).limit(limit)] + + self.update({'id__in': [feed.id for feed in feeds]}, + {'last_refreshed': now}) + return feeds |