news4 - RSS aggrigation system
Révision | c564c0bf8173fa7738be983e55116c743d5bbdd3 (tree) |
---|---|
l'heure | 2012-11-01 05:13:49 |
Auteur | hylom <hylom@hylo...> |
Commiter | hylom |
add configloader.py
@@ -0,0 +1,27 @@ | ||
1 | +# configloader.py | |
2 | +# -*- config: utf-8 -*- | |
3 | + | |
4 | +import ConfigParser | |
5 | + | |
6 | +CONFIG_FILE = 'sources.ini' | |
7 | + | |
8 | +def load(): | |
9 | + 'parse .ini file and create config object' | |
10 | + config = ConfigParser.SafeConfigParser() | |
11 | + fp = open(CONFIG_FILE, 'r') | |
12 | + config.readfp(fp) | |
13 | + fp.close() | |
14 | + sources = [] | |
15 | + for section in config.sections(): | |
16 | + source = {} | |
17 | + source["name"] = section | |
18 | + source["source"] = config.get(section, 'source') | |
19 | + source["url"] = config.get(section, 'url') | |
20 | + if config.has_option(section, 'filters'): | |
21 | + filters = config.get(section, 'filters').split(',') | |
22 | + filters = [x.strip() for x in filters] | |
23 | + source["filters"] = filters | |
24 | + sources.append(source) | |
25 | + return sources | |
26 | + | |
27 | + |