aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--pyaggr3g470r/templates/management.html2
-rwxr-xr-xpyaggr3g470r/utils.py23
2 files changed, 16 insertions, 9 deletions
diff --git a/pyaggr3g470r/templates/management.html b/pyaggr3g470r/templates/management.html
index 8cadeb3d..4a124a02 100644
--- a/pyaggr3g470r/templates/management.html
+++ b/pyaggr3g470r/templates/management.html
@@ -37,7 +37,7 @@
<a href="/export_opml/" class="btn btn-default">{{ _('Export feeds to OPML') }}</a>
<h1>{{ _('Data liberation') }}</h1>
<form action="" method="post" id="formImportJSON" enctype="multipart/form-data">
- <span class="btn btn-default btn-file">{{ _('Import account') }} (<span class="text-info">*.jsonl</span>)<input type="file" name="jsonfile" /></span>
+ <span class="btn btn-default btn-file">{{ _('Import account') }} (<span class="text-info">*.json</span>)<input type="file" name="jsonfile" /></span>
<button class="btn btn-default" type="submit">OK</button>
</form>
<br />
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
bgstack15