From 63dc58ea5dc82d4ab0984101798fd8a813187450 Mon Sep 17 00:00:00 2001 From: Brett Parker Date: Wed, 19 Dec 2007 10:58:03 +0000 Subject: [PATCH] Starting point of rss2maildir: * Config parser * Options parser --- CHANGES | 4 +++ README | 15 +++++++++ rss2maildir.conf.example | 8 +++++ rss2maildir.py | 66 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 CHANGES create mode 100644 README create mode 100644 rss2maildir.conf.example create mode 100755 rss2maildir.py diff --git a/CHANGES b/CHANGES new file mode 100644 index 0000000..bdb9fd5 --- /dev/null +++ b/CHANGES @@ -0,0 +1,4 @@ +2007-12-19 +---------- + +Initial starting points, config parser and option parsers diff --git a/README b/README new file mode 100644 index 0000000..74b04f4 --- /dev/null +++ b/README @@ -0,0 +1,15 @@ +rss2maildir +========= + +Introduction +------------ + +rss2maildir takes rss feeds and creates a maildir of messages for each of the +feeds, new items become "new", updated entries also get marked as new when they +are updated. Each feed becomes it's own maildir which can be named as you like. + +Usage +----- + +Create a config file containing the feeds and their "names" - the names will be +used as the directory name of the maildir for the feed. diff --git a/rss2maildir.conf.example b/rss2maildir.conf.example new file mode 100644 index 0000000..677687a --- /dev/null +++ b/rss2maildir.conf.example @@ -0,0 +1,8 @@ +[general] +maildir_root = RSSMaildir + +[http://www.sommitrealweird.co.uk/blog/?flav=atom] +name = Brett Parker +email = iDunno@sommitrealweird.co.uk +maildir = sommitrealweird + diff --git a/rss2maildir.py b/rss2maildir.py new file mode 100755 index 0000000..cece696 --- /dev/null +++ b/rss2maildir.py @@ -0,0 +1,66 @@ +#!/usr/bin/python + +import mailbox +import sys +import os + +from optparse import OptionParser +from ConfigParser import SafeConfigParser + +# first off, parse the command line arguments + +oparser = OptionParser() +oparser.add_option( + "-c", "--conf", dest="conf", + help="location of config file" + ) + +(options, args) = oparser.parse_args() + +# check for the configfile + +configfile = None + +if options.conf != None: + # does the file exist? + try: + os.stat(options.conf) + configfile = options.conf + except: + # should exit here as the specified file doesn't exist + sys.stderr.write("Config file %s does not exist. Exiting.\n" %(options.conf,)) + sys.exit(2) +else: + # check through the default locations + try: + os.stat("%s/.rss2maildir.conf" %(os.environ["HOME"],)) + configfile = "%s/.rss2maildir.conf" %(os.environ["HOME"],) + except: + try: + os.stat("/etc/rss2maildir.conf") + configfile = "/etc/rss2maildir.conf" + except: + sys.stderr.write("No config file found. Exiting.\n") + sys.exit(2) + +# Right - if we've got this far, we've got a config file, now for the hard +# bits... + +scp = SafeConfigParser() +scp.read(configfile) + +maildir_root = "RSSMaildir" + +if scp.has_option("general", "maildir_root"): + maildir_root = scp.get("general", "maildir_root") + +feeds = scp.sections() +try: + feeds.remove("general") +except: + pass + +for section in feeds: + print section + print "-" * len(section) + print scp.items(section) -- 2.30.2