diff options
author | Cédric Bonhomme <kimble.mandel+bitbucket@gmail.com> | 2015-03-04 07:48:14 +0100 |
---|---|---|
committer | Cédric Bonhomme <kimble.mandel+bitbucket@gmail.com> | 2015-03-04 07:48:14 +0100 |
commit | 1c0ba8fad47489ce987e628605fd106f981d8075 (patch) | |
tree | b381e4c8c910b2f2f282f6dadbda1a8c1938e358 /pyaggr3g470r/views/api/article.py | |
parent | Typo. (diff) | |
parent | adding refresh rate to the profile form (diff) | |
download | newspipe-1c0ba8fad47489ce987e628605fd106f981d8075.tar.gz newspipe-1c0ba8fad47489ce987e628605fd106f981d8075.tar.bz2 newspipe-1c0ba8fad47489ce987e628605fd106f981d8075.zip |
Merged in jaesivsm/pyaggr3g470r/evol/api (pull request #6)
Evolution Arch, API and new crawler
Diffstat (limited to 'pyaggr3g470r/views/api/article.py')
-rw-r--r-- | pyaggr3g470r/views/api/article.py | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/pyaggr3g470r/views/api/article.py b/pyaggr3g470r/views/api/article.py new file mode 100644 index 00000000..17881412 --- /dev/null +++ b/pyaggr3g470r/views/api/article.py @@ -0,0 +1,58 @@ +from flask import g +import dateutil.parser + +from pyaggr3g470r.controllers import ArticleController +from pyaggr3g470r.views.api.common import PyAggAbstractResource,\ + PyAggResourceNew, \ + PyAggResourceExisting, \ + PyAggResourceMulti + + +ARTICLE_ATTRS = {'feed_id': {'type': str}, + 'entry_id': {'type': str}, + 'link': {'type': str}, + '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') |