diff --git a/scripts/mkEvents.csh b/scripts/mkEvents.csh index a4cb770..4b6d670 100755 --- a/scripts/mkEvents.csh +++ b/scripts/mkEvents.csh @@ -1 +1 @@ -curl -o events.xml "https://ariadne.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query?starttime=2014-08-01&orderby=time&minlat=50.92&maxlat=52.76&minlon=4.26&maxlon=9.74&minmag=1.1" +curl -o events.xml "https://ariadne.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query?starttime=2015-04-01&orderby=time&minlat=50.92&maxlat=52.76&minlon=4.26&maxlon=9.74&minmag=1.1" diff --git a/scripts/mkGeolocationTable.py b/scripts/mkGeolocationTable.py index fd2a891..64082c5 100755 --- a/scripts/mkGeolocationTable.py +++ b/scripts/mkGeolocationTable.py @@ -39,6 +39,8 @@ def mkGeolocationTable(file=''): import xml.etree.ElementTree as ET from sys import stdin import warnings + from time import sleep + from geopy.geocoders import Photon import urllib2 as URL import json as JSON @@ -51,6 +53,7 @@ def mkGeolocationTable(file=''): warnings.formatwarning = simple_warning # try loading the file + geolocationTable = {} if file : try: jsonfile = open(file) @@ -62,6 +65,7 @@ def mkGeolocationTable(file=''): # parse event.xml DOM = ET.parse(stdin).getroot() + geolocator = Photon() # iterate over all events for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces): @@ -75,9 +79,32 @@ def mkGeolocationTable(file=''): elif evaluationMode == 'automatic': warnings.warn('Skipping automatic event %s' %(publicID)) else: + try: + location = geolocator.reverse("{lat}, {lng}".format(lat=lat, lng=lng)) + except: + warnings.warn('Reverse Geolocation failed. Skipping event.') + continue + place = [] + try: + place = location.raw['properties']['city'] + except KeyError: + try: + place = location.raw['properties']['town'] + except KeyError: + try: + place = location.raw['properties']['village'] + except KeyError: + try: + place = location.raw['properties']['county'] + except KeyError: + warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url)) + geolocationTable[publicID] = place + sleep(1.1) + + ''' #warnings.warn('Processing event %s' %publicID) # send and evaluate nominatim request - url = 'https://open.mapquestapi.com/nominatim/v1/reverse.php?lat={0}&lon={1}&zoom=10&format=json'.format(lat, lng) + url = 'https://open.mapquestapi.com/nominatim/v1/reverse.php?key=oE512xGQxeH1n2cueacJ6xzRv7qFlCib&lat={0}&lon={1}&zoom=10&format=json'.format(lat, lng) response = URL.urlopen(url) if ( response.msg == 'OK' ): data = JSON.loads(response.read()) @@ -106,6 +133,7 @@ def mkGeolocationTable(file=''): warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url)) else: warnings.warn('Request {0} failed'.format(url)) + ''' # dump json print 'var geolocationTable = '+JSON.dumps(geolocationTable, sort_keys=True)+';' diff --git a/www/index.html.de b/www/index.html.de index 2ed0153..5cb2541 100755 --- a/www/index.html.de +++ b/www/index.html.de @@ -112,7 +112,7 @@ Symbole:

- Nominatim Search Courtesy of MapQuest Mapquest Logo + Reverse Geolocation courtesy of Photon by Komoot

@@ -173,7 +173,7 @@ - +
diff --git a/www/index.html.en b/www/index.html.en index 0474a92..619ca49 100755 --- a/www/index.html.en +++ b/www/index.html.en @@ -116,7 +116,7 @@ Symbols:

- Nominatim Search Courtesy of MapQuest Mapquest Logo + Reverse Geolocation courtesy of Photon by Komoot