aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--README.rst2
-rw-r--r--pyaggr3g470r/rest.py7
2 files changed, 4 insertions, 5 deletions
diff --git a/README.rst b/README.rst
index 841a06ec..c3e494a3 100644
--- a/README.rst
+++ b/README.rst
@@ -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,
bgstack15