diff options
author | Eric Anderson <ejona86@gmail.com> | 2010-08-14 12:28:32 -0500 |
---|---|---|
committer | Eric Anderson <ejona86@gmail.com> | 2010-08-15 13:58:33 -0500 |
commit | d3d34b73a427973c450d705e9a6acf496c5e9384 (patch) | |
tree | 9719702ac596ff54cc454a18006b574b6105dce1 | |
parent | 8ab545b6b0453d2bd05017b4dca07d09b313dbbc (diff) | |
download | feed-transmission-d3d34b73a427973c450d705e9a6acf496c5e9384.tar.gz feed-transmission-d3d34b73a427973c450d705e9a6acf496c5e9384.zip |
Use JSON configuration format instead of INI based
-rw-r--r-- | feed-transmission.example.ini | 16 | ||||
-rw-r--r-- | feed-transmission.example.json | 14 | ||||
-rwxr-xr-x | feed-transmission.py | 37 |
3 files changed, 29 insertions, 38 deletions
diff --git a/feed-transmission.example.ini b/feed-transmission.example.ini deleted file mode 100644 index 857f177..0000000 --- a/feed-transmission.example.ini +++ /dev/null @@ -1,16 +0,0 @@ -; main section -[config] -; comma-delimited list of feeds. Name is used to look up section. -feeds: example.com - -; name is not used except by 'feeds' key in 'config' section -[example.com] -; RSS/Atom feed url to fetch -url: https://example.com/rss.php -; number of seconds to delay between fetches of feed -poll_delay: 3600 -; 'match'-prefixed items are OR'ed together to form a whitelist of items to -; download. The value should be a regular expression -match1: .*Thread: Some thread -match2: .*Thread: Some other thread - diff --git a/feed-transmission.example.json b/feed-transmission.example.json new file mode 100644 index 0000000..d934246 --- /dev/null +++ b/feed-transmission.example.json @@ -0,0 +1,14 @@ +{ + "feeds": [ + { + "matches": [ + ".*Thread: Some thread", + ".*Thread: Some other thread" + ], + "name": "example.com", + "poll_delay": 3600, + "url": "https://example.com/rss.php" + } + ] +} + 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() |