Merging trunk with branches/life.
This commit is contained in:
		
						commit
						02679c30b0
					
				
				
				Notes:
				
					subgit
				
				2018-03-07 17:58:46 +01:00 
			
			r608 www/branches/life
| @ -1,16 +1,34 @@ | ||||
| #! /usr/bin/env python | ||||
| # -*- coding: utf-8 -*- | ||||
| # $Id$ | ||||
| 
 | ||||
| ''' | ||||
| Script to lookup city names of events with Nominatim service | ||||
| 	Script to lookup city names of events with Nominatim service | ||||
| 
 | ||||
| The input should be an valid quakeML file passed to stdin. | ||||
| The output will will be a javascript structure to be included in the | ||||
| SeisObs map service. | ||||
| 	The input should be an valid quakeML file passed to stdin. | ||||
| 	The output will will be a javascript structure to be included in the | ||||
| 	SeisObs map service. | ||||
| 
 | ||||
| the script should be updated regulary keep the total number of all | ||||
| AJAX calls to the Nominatim service small | ||||
| 	The script should be updated regulary keep the total number of all | ||||
| 	AJAX calls to the Nominatim service small, e. g. : | ||||
| 	curl -s "https://ariadne.geophysik.ruhr-uni-bochum.de/fdsnws/event/1/query?minlat=50&maxlat=54&minlon=3&maxlon=10&minmag=1" | mkGeolocationTable.py > geolocationTable.js | ||||
| 
 | ||||
| 	License | ||||
| 	Copyright 2014 Kasper D. Fischer <kasper.fischer@rub.de> | ||||
| 
 | ||||
| 	This program is free software: you can redistribute it and/or modify it | ||||
| 	under the terms of the GNU General Public License as published by the Free | ||||
| 	Software Foundation, either version 3 of the License, or (at your option) | ||||
| 	any later version. | ||||
| 
 | ||||
| 	This program is distributed in the hope that it will be useful, but | ||||
| 	WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||||
| 	or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||||
| 	for more details. | ||||
| 
 | ||||
| 	You should have received a copy of the GNU General Public License along | ||||
| 	with this program. If not, see http://www.gnu.org/licenses/. | ||||
| 
 | ||||
| 	$Id$ | ||||
| ''' | ||||
| 
 | ||||
| # imports | ||||
| @ -19,6 +37,7 @@ try: | ||||
| except ImportError: | ||||
| 	import xml.etree.ElementTree as ET | ||||
| from sys import stdin | ||||
| import warnings | ||||
| import urllib2 as URL | ||||
| import json as JSON | ||||
| 
 | ||||
| @ -29,9 +48,12 @@ namespaces = {'sc3': 'http://geofon.gfz-potsdam.de/ns/seiscomp3-schema/0.7', | ||||
| # initialise variables | ||||
| geolocationTable = {}; | ||||
| 
 | ||||
| def simple_warning(message, category, filename, lineno, file=None, line=None): | ||||
| 	return 'Warning: %s\n' % (message) | ||||
| warnings.formatwarning = simple_warning | ||||
| 
 | ||||
| # parse event.xml | ||||
| DOM = ET.parse(stdin).getroot() | ||||
| #DOM = ET.parse('../www/event.xml').getroot() | ||||
| 
 | ||||
| # iterate over all events | ||||
| for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces): | ||||
| @ -44,7 +66,11 @@ for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces): | ||||
| 	if ( response.msg == 'OK' ): | ||||
| 		data = JSON.loads(response.read()) | ||||
| 		try: | ||||
| 			city = data['address']['city'] | ||||
| 			try: | ||||
| 				city = data['address']['city'] | ||||
| 			except: | ||||
| 				warnings.warn('Using county instead of city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url)) | ||||
| 				city = data['address']['county'] | ||||
| 			country = data['address']['country'] | ||||
| 			countryCode = data['address']['country_code'].upper() | ||||
| 			value = city | ||||
| @ -52,10 +78,8 @@ for event in DOM.iterfind('qml:eventParameters/qml:event', namespaces): | ||||
| 				value = '{0} ({1})'.format(value, countryCode) | ||||
| 			geolocationTable[publicID] = value | ||||
| 		except: | ||||
| 			print 'Could not etract city for event {0}'.format(publicID) | ||||
| 			warnings.warn('Could not extract city for event {0} at {1} N / {2} E (URL: {3})'.format(publicID, lat, lng, url)) | ||||
| 	else: | ||||
| 		print 'Request {0} failed'.format(url) | ||||
| 		warnings.warn('Request {0} failed'.format(url)) | ||||
| # dump json | ||||
| print 'var geolocationTable = '+JSON.dumps(geolocationTable) | ||||
| 
 | ||||
| 
 | ||||
| print 'var geolocationTable = '+JSON.dumps(geolocationTable)+';' | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user