-
Notifications
You must be signed in to change notification settings - Fork 3
/
run
executable file
·52 lines (39 loc) · 1.1 KB
/
run
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
#!/usr/bin/env python
import sys
import os
import traceback
import pprint as pp
import logging
# set global HTTP timeouts to 10 seconds
import socket
socket.setdefaulttimeout(10)
# name of the task comes first
task_name = sys.argv[1]
# parse any command line flags off
options = {}
for arg in sys.argv[2:]:
if arg.startswith("--"):
if "=" in arg:
key, value = arg.split('=')
else:
key, value = arg, True
key = key.split("--")[1]
if value == 'True': value = True
elif value == 'False': value = False
options[key.lower()] = value
# configure logging
if options.get('debug', False):
log_level = "debug"
else:
log_level = options.get("log", "warn")
if log_level not in ["debug", "info", "warn", "error"]:
print "Invalid log level (specify: debug, info, warn, error)."
sys.exit(1)
logging.basicConfig(format='%(message)s', level=log_level.upper())
# depends on scrapers/[scraper_name].py being present relative to this directory
sys.path.append("scrapers")
import utils
try:
__import__(task_name).run(options)
except Exception as exception:
utils.admin(exception)