Starting point of rss2maildir:
[rss2maildir.git] / rss2maildir.py
1 #!/usr/bin/python
2
3 import mailbox
4 import sys
5 import os
6
7 from optparse import OptionParser
8 from ConfigParser import SafeConfigParser
9
10 # first off, parse the command line arguments
11
12 oparser = OptionParser()
13 oparser.add_option(
14     "-c", "--conf", dest="conf",
15     help="location of config file"
16     )
17
18 (options, args) = oparser.parse_args()
19
20 # check for the configfile
21
22 configfile = None
23
24 if options.conf != None:
25     # does the file exist?
26     try:
27         os.stat(options.conf)
28         configfile = options.conf
29     except:
30         # should exit here as the specified file doesn't exist
31         sys.stderr.write("Config file %s does not exist. Exiting.\n" %(options.conf,))
32         sys.exit(2)
33 else:
34     # check through the default locations
35     try:
36         os.stat("%s/.rss2maildir.conf" %(os.environ["HOME"],))
37         configfile = "%s/.rss2maildir.conf" %(os.environ["HOME"],)
38     except:
39         try:
40             os.stat("/etc/rss2maildir.conf")
41             configfile = "/etc/rss2maildir.conf"
42         except:
43             sys.stderr.write("No config file found. Exiting.\n")
44             sys.exit(2)
45
46 # Right - if we've got this far, we've got a config file, now for the hard
47 # bits...
48
49 scp = SafeConfigParser()
50 scp.read(configfile)
51
52 maildir_root = "RSSMaildir"
53
54 if scp.has_option("general", "maildir_root"):
55     maildir_root = scp.get("general", "maildir_root")
56
57 feeds = scp.sections()
58 try:
59     feeds.remove("general")
60 except:
61     pass
62
63 for section in feeds:
64     print section
65     print "-" * len(section)
66     print scp.items(section)