aboutsummaryrefslogtreecommitdiff
path: root/pyaggr3g470r/views/api/article.py
diff options
context:
space:
mode:
authorFrançois Schmidts <francois.schmidts@gmail.com>2015-03-01 03:20:12 +0100
committerFrançois Schmidts <francois.schmidts@gmail.com>2015-03-03 22:23:02 +0100
commit5572851eca3b2f1bc56aed7232284acc436d2f49 (patch)
treeb8f425333804ca06a4a16600b4c4c0bfcdf4cff7 /pyaggr3g470r/views/api/article.py
parentcontinuing refacto (diff)
downloadnewspipe-5572851eca3b2f1bc56aed7232284acc436d2f49.tar.gz
newspipe-5572851eca3b2f1bc56aed7232284acc436d2f49.tar.bz2
newspipe-5572851eca3b2f1bc56aed7232284acc436d2f49.zip
new crawler with cache control and error handling
Diffstat (limited to 'pyaggr3g470r/views/api/article.py')
-rw-r--r--pyaggr3g470r/views/api/article.py36
1 files changed, 29 insertions, 7 deletions
diff --git a/pyaggr3g470r/views/api/article.py b/pyaggr3g470r/views/api/article.py
index ebda6247..17881412 100644
--- a/pyaggr3g470r/views/api/article.py
+++ b/pyaggr3g470r/views/api/article.py
@@ -1,36 +1,58 @@
from flask import g
+import dateutil.parser
from pyaggr3g470r.controllers import ArticleController
-from pyaggr3g470r.views.api.common import PyAggResourceNew, \
+from pyaggr3g470r.views.api.common import PyAggAbstractResource,\
+ PyAggResourceNew, \
PyAggResourceExisting, \
PyAggResourceMulti
-ARTICLE_ATTRS = {'title': {'type': str},
- 'content': {'type': str},
+ARTICLE_ATTRS = {'feed_id': {'type': str},
+ 'entry_id': {'type': str},
'link': {'type': str},
- 'date': {'type': str},
- 'feed_id': {'type': int},
- 'like': {'type': bool},
- 'readed': {'type': bool}}
+ 'title': {'type': str},
+ 'readed': {'type': bool}, 'like': {'type': bool},
+ 'content': {'type': str},
+ 'date': {'type': str}, 'retrieved_date': {'type': str}}
class ArticleNewAPI(PyAggResourceNew):
controller_cls = ArticleController
attrs = ARTICLE_ATTRS
+ to_date = ['date', 'retrieved_date']
class ArticleAPI(PyAggResourceExisting):
controller_cls = ArticleController
attrs = ARTICLE_ATTRS
+ to_date = ['date', 'retrieved_date']
class ArticlesAPI(PyAggResourceMulti):
controller_cls = ArticleController
attrs = ARTICLE_ATTRS
+ to_date = ['date', 'retrieved_date']
+
+
+class ArticlesChallenge(PyAggAbstractResource):
+ controller_cls = ArticleController
+ attrs = {'ids': {'type': list, 'default': []}}
+ to_date = ['date', 'retrieved_date']
+
+ def get(self):
+ parsed_args = self.reqparse_args()
+ for id_dict in parsed_args['ids']:
+ for key in self.to_date:
+ if key in id_dict:
+ id_dict[key] = dateutil.parser.parse(id_dict[key])
+
+ return self.controller.challenge(parsed_args['ids'])
g.api.add_resource(ArticleNewAPI, '/article', endpoint='article_new.json')
g.api.add_resource(ArticleAPI, '/article/<int:obj_id>',
endpoint='article.json')
g.api.add_resource(ArticlesAPI, '/articles', endpoint='articles.json')
+g.api.add_resource(ArticlesChallenge, '/articles/challenge',
+ endpoint='articles_challenge.json')
bgstack15