diff options
Diffstat (limited to 'src/web')
-rw-r--r-- | src/web/controllers/article.py | 3 | ||||
-rw-r--r-- | src/web/lib/crawler.py | 7 | ||||
-rw-r--r-- | src/web/models/__init__.py | 3 | ||||
-rw-r--r-- | src/web/models/article.py | 11 | ||||
-rw-r--r-- | src/web/models/feed.py | 1 | ||||
-rw-r--r-- | src/web/views/api/__init__.py | 4 | ||||
-rw-r--r-- | src/web/views/api/article.py | 7 | ||||
-rw-r--r-- | src/web/views/api/feed.py | 13 |
8 files changed, 26 insertions, 23 deletions
diff --git a/src/web/controllers/article.py b/src/web/controllers/article.py index 8b6926b7..a8788f46 100644 --- a/src/web/controllers/article.py +++ b/src/web/controllers/article.py @@ -34,8 +34,7 @@ class ArticleController(AbstractController): .group_by(Article.feed_id).all()) def count_by_user_id(self, **filters): - return dict(db.session.query(Article.user_id, - func.count(Article.id)) + return dict(db.session.query(Article.user_id, func.count(Article.id)) .filter(*self._to_filters(**filters)) .group_by(Article.user_id).all()) diff --git a/src/web/lib/crawler.py b/src/web/lib/crawler.py index 7343ea4d..f480fe96 100644 --- a/src/web/lib/crawler.py +++ b/src/web/lib/crawler.py @@ -18,7 +18,6 @@ import json import logging import feedparser from datetime import datetime, timedelta -from functools import wraps from time import strftime, gmtime from concurrent.futures import ThreadPoolExecutor from requests_futures.sessions import FuturesSession @@ -132,7 +131,7 @@ class PyAggUpdater(AbstractCrawler): {key: "%s -> %s" % (up_feed[key], self.feed.get(key)) for key in up_feed if up_feed[key] != self.feed.get(key)}) - future = self.query_pyagg('put', 'feed/%d' % self.feed['id'], up_feed) + self.query_pyagg('put', 'feed/%d' % self.feed['id'], up_feed) class FeedCrawler(AbstractCrawler): @@ -144,8 +143,8 @@ class FeedCrawler(AbstractCrawler): def clean_feed(self): """Will reset the errors counters on a feed that have known errors""" if self.feed.get('error_count') or self.feed.get('last_error'): - future = self.query_pyagg('put', 'feed/%d' % self.feed['id'], - {'error_count': 0, 'last_error': ''}) + self.query_pyagg('put', 'feed/%d' % self.feed['id'], + {'error_count': 0, 'last_error': ''}) def callback(self, response): """will fetch the feed and interprete results (304, etag) or will diff --git a/src/web/models/__init__.py b/src/web/models/__init__.py index 54168279..81ebe361 100644 --- a/src/web/models/__init__.py +++ b/src/web/models/__init__.py @@ -31,8 +31,9 @@ from .role import Role from .user import User from .article import Article from .icon import Icon +from .category import Category -__all__ = ['Feed', 'Role', 'User', 'Article', 'Icon'] +__all__ = ['Feed', 'Role', 'User', 'Article', 'Icon', 'Category'] import os diff --git a/src/web/models/article.py b/src/web/models/article.py index 54eefe75..44a4234d 100644 --- a/src/web/models/article.py +++ b/src/web/models/article.py @@ -32,10 +32,8 @@ from sqlalchemy import asc, desc class Article(db.Model): - """ - Represent an article from a feed. - """ - id = db.Column(db.Integer, primary_key=True) + "Represent an article from a feed." + id = db.Column(db.Integer(), primary_key=True) entry_id = db.Column(db.String()) link = db.Column(db.String()) title = db.Column(db.String()) @@ -46,8 +44,9 @@ class Article(db.Model): date = db.Column(db.DateTime(), default=datetime.now) retrieved_date = db.Column(db.DateTime(), default=datetime.now) - user_id = db.Column(db.Integer, db.ForeignKey('user.id')) - feed_id = db.Column(db.Integer, db.ForeignKey('feed.id')) + user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) + feed_id = db.Column(db.Integer(), db.ForeignKey('feed.id')) + category_id = db.Column(db.Integer(), db.ForeignKey('category.id')) def previous_article(self): """ diff --git a/src/web/models/feed.py b/src/web/models/feed.py index 59456a7f..87616e02 100644 --- a/src/web/models/feed.py +++ b/src/web/models/feed.py @@ -56,6 +56,7 @@ class Feed(db.Model): # relationship icon_url = db.Column(db.String(), db.ForeignKey('icon.url'), default=None) user_id = db.Column(db.Integer(), db.ForeignKey('user.id')) + category_id = db.Column(db.Integer(), db.ForeignKey('category.id')) articles = db.relationship('Article', backref='source', lazy='dynamic', cascade='all,delete-orphan', order_by=desc("Article.date")) diff --git a/src/web/views/api/__init__.py b/src/web/views/api/__init__.py index 24472ebe..ed3bd702 100644 --- a/src/web/views/api/__init__.py +++ b/src/web/views/api/__init__.py @@ -26,6 +26,6 @@ __revision__ = "$Date: 2014/07/05 $" __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "AGPLv3" -from web.views.api import article, feed +from web.views.api import article, feed, category -__all__ = ['article', 'feed'] +__all__ = ['article', 'feed', 'category'] diff --git a/src/web/views/api/article.py b/src/web/views/api/article.py index 51844b20..23c5c495 100644 --- a/src/web/views/api/article.py +++ b/src/web/views/api/article.py @@ -13,12 +13,15 @@ from web.views.api.common import PyAggAbstractResource,\ ARTICLE_ATTRS = {'user_id': {'type': int}, 'feed_id': {'type': int}, + 'category_id': {'type': int}, 'entry_id': {'type': str}, 'link': {'type': str}, 'title': {'type': str}, - 'readed': {'type': bool}, 'like': {'type': bool}, + 'readed': {'type': bool}, + 'like': {'type': bool}, 'content': {'type': str}, - 'date': {'type': str}, 'retrieved_date': {'type': str}} + 'date': {'type': str}, + 'retrieved_date': {'type': str}} class ArticleNewAPI(PyAggResourceNew): diff --git a/src/web/views/api/feed.py b/src/web/views/api/feed.py index 2bb9814f..dd9919bf 100644 --- a/src/web/views/api/feed.py +++ b/src/web/views/api/feed.py @@ -4,19 +4,20 @@ from flask import g from web.controllers.feed import (FeedController, - DEFAULT_MAX_ERROR, - DEFAULT_LIMIT, - DEFAULT_REFRESH_RATE) + DEFAULT_MAX_ERROR, + DEFAULT_LIMIT, + DEFAULT_REFRESH_RATE) from web.views.api.common import PyAggAbstractResource, \ - PyAggResourceNew, \ - PyAggResourceExisting, \ - PyAggResourceMulti + PyAggResourceNew, \ + PyAggResourceExisting, \ + PyAggResourceMulti FEED_ATTRS = {'title': {'type': str}, 'description': {'type': str}, 'link': {'type': str}, 'user_id': {'type': int}, + 'category_id': {'type': int}, 'site_link': {'type': str}, 'enabled': {'type': bool, 'default': True}, 'etag': {'type': str, 'default': ''}, |