blob: 56cef9979e563a2e7225701671575fa938a05e9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
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_modified=max_last_refresh).limit(limit)]
self.update({'id__in': [feed.id for feed in feeds]},
{'last_modified': now})
return feeds
def list_last_articles(self, feed_id, limit=50):
from pyaggr3g470r.controllers import ArticleController
return ArticleController(self.user_id)._get(feed_id=feed_id)\
.order_by(ArticleController._db_cls.retrieved_date.desc())\
.limit(limit)
|