forked from THE-Port/ThePortHackathon-Pier15
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geolocator.py
52 lines (39 loc) · 939 Bytes
/
geolocator.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
from geopy.geocoders import Nominatim
geolocator = Nominatim()
f = open("cities_data.csv", "r")
f_out = open("final_data.csv", "w")
data = f.readlines()
# Name of Province : 2
# Name of Country : 1
# Name of Medicine : 3
# Result : 4
count = 0
for _d in data:
try:
d = _d.split(",")
province = d[2]
country = d[1]
name = d[3]
result = d[4]
location = geolocator.geocode(province+" , ",country)
if type(location) == type([]):
location = location[0]
lat = location.latitude
lng = location.longitude
count += 1
s = ""
s += name
s += ","
s +=str(lat)
s += ","
s += str(lng)
s += ","
s += result
s += "\n"
f_out.write(s)
f_out.close()
if count > 500:
t.sleep(80)
print f
except:
passP