-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGetCoordinatesForAllData.py
59 lines (29 loc) · 1.18 KB
/
GetCoordinatesForAllData.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
__author__ = 'chuqiao'
from geopy.geocoders import Nominatim
import EventsPortal
def getCoordinatesForAllData(sourceUrl,patternUrl):
data = EventsPortal.getAllEventsData(sourceUrl,patternUrl)
for docs in data:
latitudeField = docs['latitude']
if latitudeField == None:
geocity = docs['locationCity']
geolocator = Nominatim()
locatorCity = geocity
location = geolocator.geocode(locatorCity)
latitude = location.latitude
longitude = location.longitude
docs['latitudetest'] = latitude
docs['longitudetest'] = longitude
else:
pass
return data
def addAllDataToSolrFromUrl(sourceUrl,patternUrl,solrUrl):
"""
add data to a Solr index crawling events from a URL
"""
data = getCoordinatesForAllData(sourceUrl,patternUrl)
EventsPortal.addDataToSolr(data, solrUrl)
if __name__ == '__main__':
addAllDataToSolrFromUrl("http://bioevents-portal.org/eventsfull/test?state=published&field_type_tid=All",
"http://bioevents-portal.org/events",
"139.162.217.53:8983/solr/eventsportal/")