diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-06-13 00:05:57 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2017-06-13 00:05:57 +0200 |
commit | bd94eaea8bb31df48006b431877589fa137e761b (patch) | |
tree | 348f2564486345b3dd5f74fafc4d584f0b4f2045 /src/lib | |
parent | Updated comments. (diff) | |
download | newspipe-bd94eaea8bb31df48006b431877589fa137e761b.tar.gz newspipe-bd94eaea8bb31df48006b431877589fa137e761b.tar.bz2 newspipe-bd94eaea8bb31df48006b431877589fa137e761b.zip |
flask.jsonify now supports directly lists
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/data.py | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/src/lib/data.py b/src/lib/data.py index 75f6b8aa..9b037b90 100644 --- a/src/lib/data.py +++ b/src/lib/data.py @@ -97,7 +97,7 @@ def import_json(email, json_content): json_account = json.loads(json_content.decode("utf-8")) nb_feeds, nb_articles = 0, 0 # Create feeds: - for feed in json_account["result"]: + for feed in json_account: if None != Feed.query.filter(Feed.user_id == user.id, Feed.link == feed["link"]).first(): continue @@ -112,7 +112,7 @@ def import_json(email, json_content): nb_feeds += 1 db.session.commit() # Create articles: - for feed in json_account["result"]: + for feed in json_account: user_feed = Feed.query.filter(Feed.user_id == user.id, Feed.link == feed["link"]).first() if None != user_feed: @@ -142,26 +142,26 @@ def export_json(user): """ Export all articles of user in JSON. """ - result = [] + articles = [] for feed in user.feeds: - result.append({ - "title": feed.title, - "description": feed.description, - "link": feed.link, - "site_link": feed.site_link, - "enabled": feed.enabled, - "created_date": feed.created_date.strftime('%s'), - "articles": [ { - "title": article.title, - "link": article.link, - "content": article.content, - "readed": article.readed, - "like": article.like, - "date": article.date.strftime('%s'), - "retrieved_date": article.retrieved_date.strftime('%s') - } for article in feed.articles ] - }) - return jsonify(result=result) + articles.append({ + "title": feed.title, + "description": feed.description, + "link": feed.link, + "site_link": feed.site_link, + "enabled": feed.enabled, + "created_date": feed.created_date.strftime('%s'), + "articles": [ { + "title": article.title, + "link": article.link, + "content": article.content, + "readed": article.readed, + "like": article.like, + "date": article.date.strftime('%s'), + "retrieved_date": article.retrieved_date.strftime('%s') + } for article in feed.articles] + }) + return jsonify(articles) def import_pinboard_json(user, json_content): |