diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-04-23 22:39:32 +0200 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-04-23 22:39:32 +0200 |
commit | bcb58822eaa56fb5c41548431d3d8ad2e315ee86 (patch) | |
tree | 205a44f9e2f29a3a9c07597ccbde4c22fdecbbfe | |
parent | A message is displayed to inform the user about authorized file extension. (diff) | |
download | newspipe-bcb58822eaa56fb5c41548431d3d8ad2e315ee86.tar.gz newspipe-bcb58822eaa56fb5c41548431d3d8ad2e315ee86.tar.bz2 newspipe-bcb58822eaa56fb5c41548431d3d8ad2e315ee86.zip |
This fixes #2.
-rwxr-xr-x | pyaggr3g470r/utils.py | 64 | ||||
-rw-r--r-- | pyaggr3g470r/views.py | 5 |
2 files changed, 42 insertions, 27 deletions
diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py index 6f0bab33..ce210c20 100755 --- a/pyaggr3g470r/utils.py +++ b/pyaggr3g470r/utils.py @@ -83,39 +83,50 @@ def import_opml(email, opml_file): subscriptions = opml.parse(opml_file) except Exception as e: raise e - nb = 0 - for subscription in subscriptions: - try: - title = subscription.text - except: - title = "" + def read(subsubscription, nb=0): + """ + Parse recursively through the categories and sub-categories. + """ + for subscription in subsubscription: + + if len(subscription) != 0: + nb = read(subscription, nb) + else: + + try: + title = subscription.text - try: - description = subscription.description - except: - description = "" + except: + title = "" - try: - link = subscription.xmlUrl - except: - continue + try: + description = subscription.description + except: + description = "" - if None != Feed.query.filter(Feed.link == link).first(): - continue + try: + link = subscription.xmlUrl + except: + continue - try: - site_link = subscription.htmlUrl - except: - site_link = "" + if None != Feed.query.filter(Feed.link == link).first(): + continue + + try: + site_link = subscription.htmlUrl + except: + site_link = "" - new_feed = Feed(title=title, description=description, link=link, site_link=site_link, email_notification=False, enabled=True) + new_feed = Feed(title=title, description=description, link=link, site_link=site_link, email_notification=False, enabled=True) - user.feeds.append(new_feed) - nb += 1 + user.feeds.append(new_feed) + nb += 1 + return nb + nb = read(subscriptions) db.session.commit() - return nb, len(subscriptions)-nb + return nb def clean_url(url): """ @@ -232,3 +243,8 @@ def search_feed(url): #return urllib.parse.urljoin(url, feed_link['href']) return feed_link['href'] return None + + +if __name__ == "__main__": + import_opml("root@pyAggr3g470r.localhost", "./var/feeds_test.opml") + #import_opml("root@pyAggr3g470r.localhost", "./var/pyAggr3g470r.opml")
\ No newline at end of file diff --git a/pyaggr3g470r/views.py b/pyaggr3g470r/views.py index 1afcecb2..a00fcb2a 100644 --- a/pyaggr3g470r/views.py +++ b/pyaggr3g470r/views.py @@ -499,9 +499,8 @@ def management(): opml_path = os.path.join("./pyaggr3g470r/var/", data.filename) data.save(opml_path) try: - nb, nb_already = utils.import_opml(g.user.email, opml_path) - flash(str(nb) + " feeds imported (" + str(nb_already) + \ - " already in the database).", "success") + nb = utils.import_opml(g.user.email, opml_path) + flash(str(nb) + " feeds imported.", "success") except Exception as e: flash("Impossible to import the new feeds.", "danger") |