From 64d46ffda837e88596fae19c20d1d55467932668 Mon Sep 17 00:00:00 2001 From: Cédric Bonhomme Date: Sun, 9 Feb 2014 16:10:49 +0100 Subject: It is now possible to import OPML files. --- pyaggr3g470r/utils.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'pyaggr3g470r/utils.py') 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 -- cgit