diff options
Diffstat (limited to 'newspipe/web/views/api/v2/article.py')
-rw-r--r-- | newspipe/web/views/api/v2/article.py | 32 |
1 files changed, 19 insertions, 13 deletions
diff --git a/newspipe/web/views/api/v2/article.py b/newspipe/web/views/api/v2/article.py index 2be286c6..8da6c6dd 100644 --- a/newspipe/web/views/api/v2/article.py +++ b/newspipe/web/views/api/v2/article.py @@ -6,8 +6,12 @@ from flask_restful import Api from web.views.common import api_permission from web.controllers import ArticleController -from web.views.api.v2.common import (PyAggAbstractResource, - PyAggResourceNew, PyAggResourceExisting, PyAggResourceMulti) +from web.views.api.v2.common import ( + PyAggAbstractResource, + PyAggResourceNew, + PyAggResourceExisting, + PyAggResourceMulti, +) class ArticleNewAPI(PyAggResourceNew): @@ -24,30 +28,32 @@ class ArticlesAPI(PyAggResourceMulti): class ArticlesChallenge(PyAggAbstractResource): controller_cls = ArticleController - attrs = {'ids': {'type': list, 'default': []}} + attrs = {"ids": {"type": list, "default": []}} @api_permission.require(http_exception=403) def get(self): - parsed_args = self.reqparse_args(right='read') + parsed_args = self.reqparse_args(right="read") # collecting all attrs for casting purpose - attrs = self.controller_cls._get_attrs_desc('admin') - for id_dict in parsed_args['ids']: + attrs = self.controller_cls._get_attrs_desc("admin") + for id_dict in parsed_args["ids"]: keys_to_ignore = [] for key in id_dict: if key not in attrs: keys_to_ignore.append(key) - if issubclass(attrs[key]['type'], datetime): + if issubclass(attrs[key]["type"], datetime): id_dict[key] = dateutil.parser.parse(id_dict[key]) for key in keys_to_ignore: del id_dict[key] - result = list(self.controller.challenge(parsed_args['ids'])) + result = list(self.controller.challenge(parsed_args["ids"])) return result or None, 200 if result else 204 + api = Api(current_app, prefix=API_ROOT) -api.add_resource(ArticleNewAPI, '/article', endpoint='article_new.json') -api.add_resource(ArticleAPI, '/article/<int:obj_id>', endpoint='article.json') -api.add_resource(ArticlesAPI, '/articles', endpoint='articles.json') -api.add_resource(ArticlesChallenge, '/articles/challenge', - endpoint='articles_challenge.json') +api.add_resource(ArticleNewAPI, "/article", endpoint="article_new.json") +api.add_resource(ArticleAPI, "/article/<int:obj_id>", endpoint="article.json") +api.add_resource(ArticlesAPI, "/articles", endpoint="articles.json") +api.add_resource( + ArticlesChallenge, "/articles/challenge", endpoint="articles_challenge.json" +) |