diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-06-23 10:50:58 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-06-23 10:50:58 +0200 |
commit | e1998dc76d89861c0c6fadd3badbb6a3cfbc07f1 (patch) | |
tree | 18bb43451e927b6df3c14196ae4d8b0e6ee82014 | |
parent | POST method should be defined in ArticleListAPI. (diff) | |
download | newspipe-e1998dc76d89861c0c6fadd3badbb6a3cfbc07f1.tar.gz newspipe-e1998dc76d89861c0c6fadd3badbb6a3cfbc07f1.tar.bz2 newspipe-e1998dc76d89861c0c6fadd3badbb6a3cfbc07f1.zip |
Updated README and fixed a problem when parsing the publication date of the article.
-rw-r--r-- | README.rst | 2 | ||||
-rw-r--r-- | pyaggr3g470r/rest.py | 7 |
2 files changed, 4 insertions, 5 deletions
@@ -181,7 +181,7 @@ Add an article: >>> import requests, json >>> headers = {'Content-type': 'application/json', 'Accept': 'application/json'} - >>> payload = {'link': 'http://blog.cedricbonhomme.org/2014/05/24/sortie-de-pyaggr3g470r-5-3/', 'title': 'Sortie de pyAggr3g470r 5.3', 'content':'La page principale de pyAggr3g470r a été améliorée...', 'date':str(datetime.datetime.now()), 'feed_id':'42'} + >>> payload = {'link': 'http://blog.cedricbonhomme.org/2014/05/24/sortie-de-pyaggr3g470r-5-3/', 'title': 'Sortie de pyAggr3g470r 5.3', 'content':'La page principale de pyAggr3g470r a été améliorée...', 'date':'06/23/2014 11:42 AM'), 'feed_id':'42'} >>> r = requests.post("https://pyaggr3g470r.herokuapp.com/api/v1.0/articles/0", headers=headers, auth=("your-email", "your-password"), data=json.dumps(payload)) >>> print r.content { diff --git a/pyaggr3g470r/rest.py b/pyaggr3g470r/rest.py index 2909f3cb..58500f1e 100644 --- a/pyaggr3g470r/rest.py +++ b/pyaggr3g470r/rest.py @@ -26,7 +26,8 @@ __revision__ = "$Date: 2014/06/18 $" __copyright__ = "Copyright (c) Cedric Bonhomme" __license__ = "AGPLv3" -import dateutil +import re +import dateutil.parser from functools import wraps from flask import g, Response, request, session, jsonify from flask.ext.restful import Resource, reqparse @@ -126,13 +127,11 @@ class ArticleListAPI(Resource): article_date = None try: article_date = dateutil.parser.parse(article_dict["date"], dayfirst=True) - return {"message":"bad format for the date"} except: try: # trying to clean date field from letters article_date = dateutil.parser.parse(re.sub('[A-z]', '', article_dict["date"], dayfirst=True)) - return {"message":"bad format for the date"} except: - pass + return {"message":"bad format for the date"} article = Article(link=article_dict["link"], title=article_dict["title"], content=article_dict["content"], readed=False, like=False, date=article_date, user_id=g.user.id, |