diff options
Diffstat (limited to 'feed-transmission.py')
-rwxr-xr-x | feed-transmission.py | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/feed-transmission.py b/feed-transmission.py index dbb9a8f..521fecf 100755 --- a/feed-transmission.py +++ b/feed-transmission.py @@ -7,7 +7,7 @@ import subprocess import urllib2 import tempfile import shelve -import ConfigParser +import json class App(object): def __init__(self): @@ -16,14 +16,10 @@ class App(object): self.feeds = [] def load_config(self, ini): - config = ConfigParser.RawConfigParser({}) - config.readfp(file(ini)) - feed_names = config.get("config", "feeds") - feed_names = feed_names.split(",") - for i in feed_names: - i = i.strip() + config = json.load(file(ini)) + for i in config["feeds"]: feed = Feed() - feed.load_config(config, i) + feed.load_config(i) self.add_feed(feed) def load_stor(self, data): @@ -129,28 +125,25 @@ class Feed(object): found.append(i.link) return found - def load_config(self, config, section): - url = config.get(section, "url") - poll_delay = config.getint(section, "poll_delay") - match = [] - for m in config.items(section): - if not m[0].startswith("match"): - continue + def load_config(self, config): + url = str(config["url"]) + poll_delay = int(config["poll_delay"]) + matches = list(config["matches"]) + for i, m in enumerate(matches): try: - re.compile(m[1]) + re.compile(m) except re.error: - print "Invalid regular expression at %s, %s: %s" % (section, m[0], m[1]) - match.append(m[1]) - match = "|".join(match) - match = re.compile(match) + print "Invalid regular expression in matches list with index %d: %s" % (i, m) + matches = "|".join(matches) + matches = re.compile(matches) self.url = url if poll_delay: self.poll_delay = poll_delay - self.match = match + self.match = matches if __name__ == "__main__": app = App() - app.load_config('.feed-transmission.ini') + app.load_config('.feed-transmission.json') app.load_stor(".feed-transmission.data") app.setup_env() app.main() |