aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/controllers/feed.py
diff options
context:
space:
mode:
authorCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-04-07 10:19:58 +0200
committerCédric Bonhomme <kimble.mandel+bitbucket@gmail.com>2015-04-07 10:19:58 +0200
commitc87817488673385b7f9d78020d22788c5f1d9f7d (patch)
treecc1933cd489d6c2432bb679e698dc8b4edf1edd0 /pyaggr3g470r/controllers/feed.py
parentReleased version 6.5. (diff)
parentcorrecting the way we use the controllers and adding documentation (diff)
downloadnewspipe-c87817488673385b7f9d78020d22788c5f1d9f7d.tar.gz
newspipe-c87817488673385b7f9d78020d22788c5f1d9f7d.tar.bz2
newspipe-c87817488673385b7f9d78020d22788c5f1d9f7d.zip
Merged in jaesivsm/pyaggr3g470r (pull request #7)
improving http crawler and misc correction on controller use
Diffstat (limited to 'pyaggr3g470r/controllers/feed.py')
-rw-r--r--pyaggr3g470r/controllers/feed.py21
1 files changed, 15 insertions, 6 deletions
diff --git a/pyaggr3g470r/controllers/feed.py b/pyaggr3g470r/controllers/feed.py
index 342ab88e..b99a3a7f 100644
--- a/pyaggr3g470r/controllers/feed.py
+++ b/pyaggr3g470r/controllers/feed.py
@@ -1,22 +1,31 @@
-from datetime import datetime
+import logging
+from datetime import datetime, timedelta
+
from .abstract import AbstractController
from pyaggr3g470r.models import Feed
-DEFAULT_MAX_ERROR = 3
+logger = logging.getLogger(__name__)
+DEFAULT_MAX_ERROR = 6
DEFAULT_LIMIT = 5
class FeedController(AbstractController):
_db_cls = Feed
+ def list_late(self, max_last, max_error=DEFAULT_MAX_ERROR,
+ limit=DEFAULT_LIMIT):
+ return [feed for feed in self.read(
+ error_count__lt=max_error, enabled=True,
+ last_retrieved__lt=max_last)
+ .order_by('Feed.last_retrieved')
+ .limit(limit)]
+
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).limit(limit)]
- #last_retrieved__lt=max_last).limit(limit)]
+ max_last = now - timedelta(minutes=user.refresh_rate or 60)
+ feeds = self.list_late(max_last, max_error, limit)
if feeds:
self.update({'id__in': [feed.id for feed in feeds]},
{'last_retrieved': now})
bgstack15