diff options
author | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-02-09 16:10:49 +0100 |
---|---|---|
committer | Cédric Bonhomme <cedric@cedricbonhomme.org> | 2014-02-09 16:10:49 +0100 |
commit | 64d46ffda837e88596fae19c20d1d55467932668 (patch) | |
tree | 49ae5775095d368c8b81f57277d213b34a2e1958 /pyaggr3g470r/utils.py | |
parent | Merge branch 'master' of bitbucket.org:cedricbonhomme/pyaggr3g470r (diff) | |
download | newspipe-64d46ffda837e88596fae19c20d1d55467932668.tar.gz newspipe-64d46ffda837e88596fae19c20d1d55467932668.tar.bz2 newspipe-64d46ffda837e88596fae19c20d1d55467932668.zip |
It is now possible to import OPML files.
Diffstat (limited to 'pyaggr3g470r/utils.py')
-rwxr-xr-x | pyaggr3g470r/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/pyaggr3g470r/utils.py b/pyaggr3g470r/utils.py index c214cf71..0b112615 100755 --- a/pyaggr3g470r/utils.py +++ b/pyaggr3g470r/utils.py @@ -37,6 +37,7 @@ __license__ = "GPLv3" import os import re import glob +import opml import operator import calendar @@ -46,6 +47,7 @@ from collections import Counter from contextlib import contextmanager import conf +import models # regular expression to check URL url_finders = [ \ @@ -70,6 +72,23 @@ def opened_w_error(filename, mode="r"): finally: f.close() +def import_opml(email, opml_file): + """ + Import new feeds from an OPML file. + """ + user = models.User.objects(email=email).first() + try: + subscriptions = opml.parse(opml_file) + except Exception as e: + raise e + for subscription in subscriptions: + existing_feed = [feed for feed in user.feeds if feed.link == subscription.xmlUrl] + if len(existing_feed) == 0: + new_feed = models.Feed(title=subscription.title, description=subscription.description, link=subscription.xmlUrl, \ + site_link=subscription.htmlUrl, email=False, enabled=True) + user.feeds.append(new_feed) + user.save() + def open_url(url): """ Open an URL with the proxy and the user-agent |