This repository has been archived by the owner on Feb 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run-aggregator.py
executable file
·58 lines (48 loc) · 1.81 KB
/
run-aggregator.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
#!/usr/bin/python3
# Library
import configparser
import argparse
import datetime
import logging
from os.path import join
from subprocess import call
# Local
def init():
logging.basicConfig(
filename=join('logs', str(datetime.date.today()) + '.log'),
level=logging.DEBUG,
format='[%(asctime)s]: %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
logging.info('Initializing')
parser = argparse.ArgumentParser(description='Runner script for Event aggregation')
parser.add_argument('--reset_config', action='store_true', help='Reset defaults.cfg to defaults')
parser.add_argument('--config_file', default='config/defaults.cfg', help='Specify which config file to use')
args = parser.parse_args()
# the reset config file flag was given, so we reset the config file and exit
if args.reset_config:
logging.info('Creating default config file')
default_config()
logging.info('Finished creating default config file, exiting')
exit()
config = configparser.RawConfigParser(allow_no_value=True)
config.optionxform = str
config.read(args.config_file)
return args, config
def default_config():
config = configparser.RawConfigParser(allow_no_value=True)
config.optionxform = str
config.add_section('Spiders')
config.set('Spiders', 'bostoncalendar_spider.py', '-o bostoncalendar_events.json')
with open('config/defaults.cfg', 'wt') as configfile:
config.write(configfile)
def write_to_file(content, filename):
logging.info('Writing data to "' + filename + '"')
f = open(filename, 'a+')
f.write(content)
f.close()
def main():
args, config = init()
spiders = config.items('Spiders')
for spider, args in spiders:
call(['scrapy', 'crawl', spider] + args.split(), cwd='bostonevents')
main()