-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDFTMapping.py
67 lines (59 loc) · 3.07 KB
/
DFTMapping.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
65
66
67
# DFTMapping Script
# Authors: Zeena Shawa, Jason Sklavenitis
# TODO: My takeaways: don't just choose any random method
# don't copy paste argument names thinking they are consistent
# how to add instance of package to pycharm: https://stackoverflow.com/questions/35623776/import-numpy-on-pycharm
from DataLoader import CsvDao
from GoogleAPIConnector import GoogleAPIHttpClient
if __name__ == "__main__":
data_loader = CsvDao()
addresses = data_loader.get_addresses()
print(addresses)
client = GoogleAPIHttpClient()
client.setup_places_api()
address_info_list = client.get_address_info(addresses)
place_ids = []
dental_practice_review_info = []
for address_info in address_info_list:
print(address_info)
if 'result' in address_info:
dental_practice_review_info.append(','+','.join(data_loader.get_reviews_csv_fornmat(address_info)))
place_ids.append(address_info['result']['place_id'])
# How to deal with double addresses
elif len(address_info) > 1 and 'result' in address_info[0]:
double_address_reviews = []
for address in address_info:
double_address_reviews.append(data_loader.get_reviews_csv_fornmat(address))
place_ids.append(address['result']['place_id'])
csv_format_address_reviews = ''
for column_value_index in range(len(data_loader.get_reviews_csv_fornmat(address_info[0]))):
csv_format_address_reviews += ','+'\"' + double_address_reviews[0][column_value_index] \
+ ',' + double_address_reviews[1][column_value_index] + '\"'
dental_practice_review_info.append(csv_format_address_reviews)
elif 'N/A' in address_info:
csv_format_address_reviews = ', , ,'
dental_practice_review_info.append(csv_format_address_reviews)
print("nfrvinfen")
else:
dental_practice_review_info.append(','+','.join(data_loader.get_reviews_csv_fornmat(address_info)))
place_ids.append(address_info['result']['place_id'])
client.setup_directions_matrix_api()
travel_times_London = client.get_directions_to_London(place_ids)
london_distance_list = []
for distance_object in travel_times_London:
distance_to_london = ''
if isinstance(distance_object, list):
distance_to_london += ',\"'
distance_to_london_list = []
for element in distance_object:
elements = element['rows']
distance_to_london_list.append(str(elements[0]['elements'][0]['duration']['text']))
distance_to_london += ','.join(distance_to_london_list)
distance_to_london += '\"'
else:
print(distance_object)
elements = distance_object['rows']
print(elements)
distance_to_london += ','+str(elements[0]['elements'][0]['duration']['text'])
london_distance_list.append(distance_to_london)
data_loader.write_addresses_to_file(dental_practice_review_info, london_distance_list)