-
Notifications
You must be signed in to change notification settings - Fork 2
/
run.py
64 lines (57 loc) · 2.21 KB
/
run.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
from ac.ac_geocoder import Geocoder
from ac.blds_dataset import BLDSDataset
from cities.palo_alto.palo_alto_city import PaloAltoCity
from cities.palo_alto.convert_to_dict import get_palo_alto_permits
from cities.san_jose.convert_to_dict import get_san_jose_permits
from cities.san_jose.san_jose_city import SanJoseCity
import sys, getopt
def main(argv):
city_name=''
project_id = ''
dataset_id = ''
api_token = ''
do_geocode = False
try:
opts, args = getopt.getopt(argv,"hgc:p:d:t:",["city=","projectid=","datasetid=","token"])
except getopt.GetoptError:
print('run.py -c <city> -p <project_id> -d <dataset_id> -t <API Token>')
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print('run.py -c <city> -p <project_id> -d <dataset_id> -t <API Token>')
sys.exit()
elif opt in ("-g"):
do_geocode = True
elif opt in ("-c", "--city"):
city_name = arg
elif opt in ("-p", "--projectid"):
project_id = arg
elif opt in ("-d", "--datasetid"):
dataset_id = arg
elif opt in ("-t", "--token"):
api_token = arg
if do_geocode and city_name and project_id and dataset_id and api_token:
g = Geocoder(city_name, project_id, dataset_id, api_token)
g.geocode()
elif city_name == "San Jose" and project_id and dataset_id and api_token:
print("Process " + city_name)
permits = get_san_jose_permits()
dataset = BLDSDataset(project_id, dataset_id, api_token)
dataset.create_schema()
sj = SanJoseCity()
dataset.upload_permits(permits, sj)
elif city_name == "Palo Alto" and project_id and dataset_id and api_token:
print("Process " + city_name)
permits = get_palo_alto_permits()
dataset = BLDSDataset(project_id, dataset_id, api_token)
dataset.create_schema()
pa = PaloAltoCity()
dataset.upload_permits(permits, pa)
else:
print('Project id: ' + project_id)
print('Dataset id: ' + dataset_id)
print("City: " + city_name)
if not api_token:
print("API Token is missing")
if __name__ == "__main__":
main(sys.argv[1:])