diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-05-27 18:36:55 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-05-27 18:36:55 +0200 |
commit | 162b878c7f4a8b0e46f1d7f75194098720226fbc (patch) | |
tree | 63178c411d22734ab3ddace4d6e6d4caec77dbfa /pyaggr3g470r/utils.py | |
parent | Updated JSON export. (diff) | |
download | newspipe-162b878c7f4a8b0e46f1d7f75194098720226fbc.tar.gz newspipe-162b878c7f4a8b0e46f1d7f75194098720226fbc.tar.bz2 newspipe-162b878c7f4a8b0e46f1d7f75194098720226fbc.zip |
Account import near to be OK.
Diffstat (limited to 'pyaggr3g470r/utils.py')
-rwxr-xr-x | pyaggr3g470r/utils.py | 23 |
1 files changed, 15 insertions, 8 deletions
diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py index 22b0aa08..5e8be5f8 100755 --- a/pyaggr3g470r/utils.py +++ b/pyaggr3g470r/utils.py @@ -143,6 +143,7 @@ def import_json(email, json_file): json_account = json.loads(json_string) nb_feeds, nb_articles = 0, 0 + # Create feeds for feed in json_account["result"]: if None != Feed.query.filter(Feed.user_id == user.id, Feed.link == feed["link"]).first(): @@ -156,18 +157,24 @@ def import_json(email, json_file): nb_feeds += 1 db.session.commit() + # Create articles for feed in json_account["result"]: user_feed = Feed.query.filter(Feed.user_id == user.id, Feed.link == feed["link"]).first() if None != user_feed: for article in feed["articles"]: - new_article = Article(link=article["link"], title=article["title"], \ - content=article["content"], readed=article["readed"], like=article["like"], \ - retrieved_date=datetime.datetime.fromtimestamp(int(article["retrieved_date"])), - date=datetime.datetime.fromtimestamp(int(article["date"])), - user_id=user.id, feed_id=user_feed.id) - - user_feed.articles.append(new_article) - nb_articles += 1 + + if None == Article.query.filter(Article.user_id == user.id, + Article.feed_id == user_feed.id, + Article.link == article["link"]).first(): + + new_article = Article(link=article["link"], title=article["title"], \ + content=article["content"], readed=article["readed"], like=article["like"], \ + retrieved_date=datetime.datetime.fromtimestamp(int(article["retrieved_date"])), + date=datetime.datetime.fromtimestamp(int(article["date"])), + user_id=user.id, feed_id=user_feed.id) + + user_feed.articles.append(new_article) + nb_articles += 1 db.session.commit() return nb_feeds, nb_articles |