-
Notifications
You must be signed in to change notification settings - Fork 0
/
update_sources.py
65 lines (44 loc) · 1.55 KB
/
update_sources.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
import logging as log
import traceback
import ConfigParser
from utils import cache_object, app_prep
APP_DIR = os.path.dirname(os.path.abspath(__file__))
def _update_sources( sources ):
for key, slist in sources.items():
for s in slist:
cache_to_compare = cache_object( s )
module = __import__('scrapers.' + s, fromlist = [ 'get_urls', 'requires_moderation' ])
if (module.requires_moderation()):
cache_to_update = cache_object( key + '.moderate' )
else:
cache_to_update = cache_object( key + '.send' )
module.update_urls( cache_to_compare, cache_to_update )
cache_to_compare.save()
cache_to_update.save()
def _build_group_map(config, section):
map_ = {}
for i in range(1,9999):
try:
id_ = 'group%d' % i
map_[id_] = [ n.strip() for n in config.get ( section, id_ ).split(',') ]
except:
break
return map_
def main():
# Read config file
config = ConfigParser.RawConfigParser(allow_no_value=True)
config.readfp( open( os.path.join( APP_DIR, 'app.settings' ) ) )
# Build reverse maps for names to group names
sources = _build_group_map( config, 'sources' )
_update_sources( sources )
if __name__ == "__main__":
app_prep( 'update_sources.log' )
try:
main()
except Exception as e:
for line in traceback.format_exc().splitlines():
log.error( line )