From 8162ca0d371df35a062c1c08b42ed2f38263cf69 Mon Sep 17 00:00:00 2001 From: vv01f Date: Fri, 31 Jan 2020 00:09:49 +0100 Subject: [PATCH] modify for veb it --- create-geojson.sh | 9 +++++---- lookup.py | 29 ++++++++++++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/create-geojson.sh b/create-geojson.sh index a8e0321..ae3bd07 100755 --- a/create-geojson.sh +++ b/create-geojson.sh @@ -1,11 +1,12 @@ #!/usr/bin/env sh echo "this takes some time depending on the amount of addresses in your lists …" -for file in *-csv ; do - out=$(echo "${file}"|cut -d- -f1)".geojson" - if test -e "${out}" ; do +for file in *.csv ; do + out=$(echo "${file}"|cut -d"." -f1)".geojson" + if test -e "${out}" ; then echo "file exists: ${out}, skipping." continue fi echo ./lookup.py "${file}" - ./lookup.py "${file}" 2>/dev/null > "${out}" + ./lookup.py "${file}" > "${out}" + #~ ./lookup.py "${file}" 2>/dev/null > "${out}" done diff --git a/lookup.py b/lookup.py index f19928f..5fbe2fb 100755 --- a/lookup.py +++ b/lookup.py @@ -5,13 +5,19 @@ from geopy import Nominatim # ~ import json import sys -import sys +#disable ssl verification +import ssl +import geopy.geocoders +ctx = ssl.create_default_context() +ctx.check_hostname = False +ctx.verify_mode = ssl.CERT_NONE +geopy.geocoders.options.default_ssl_context = ctx +#/ # debug print to stderr, https://stackoverflow.com/questions/5574702/how-to-print-to-stderr-in-python def eprint(*args, **kwargs): print(*args, file=sys.stderr, **kwargs) -# ~ fn="ct-csv" if len(sys.argv) == 2: fn = sys.argv[1] else: @@ -21,9 +27,9 @@ else: sys.exit(1) # exit with error # for retreiving geo coordinates from addresses -geolocator = Nominatim(user_agent="my-mapper") -# lat: 0=111,1km,1=11km,2=1km… lng: 0=70km,1=7km,2=.7km… -precision = 2 +geolocator = Nominatim(user_agent="vebit-mapper") +# lat: 0=111,1km; 1=11km; 2=1km… lng: 0=70km; 1=7km; 2=0,7km… +precision = 1 # convert csv to geojson @@ -31,18 +37,23 @@ firstline = True # start json list print ( '{"type":"FeatureCollection","features":[' ) # get data from file +eprint( "opening: "+fn ) with open( fn, 'r' ) as fp: for place in fp: #error handling: expect - arrAddress = place.split(",") - strAddress = ",".join(arrAddress[2:6]) + arrAddress = place.split(";") + strAddress1 = str(" ".join(arrAddress[1:2])) + eprint( "… "+strAddress1 ) + strAddress2 = ",".join(arrAddress[3:5]) + eprint( "… "+strAddress2 ) + strAddress = strAddress1+","+strAddress2 eprint( "looking up: "+strAddress ) location = geolocator.geocode( strAddress ) if location is not None: # its a class # todo: ceil coords to hide true location in format string # ~ strCoordPlace = '{:s},{:.6f},{:.6f}'.format( arrAddress[3], location.latitude, location.longitude ) - geojson = '{{"type":"Feature","geometry":{{"type":"Point","coordinates":[{:.'+str(precision)+'f},{:.'+str(precision)+'f}]}},"properties":{{"name":"{:s}","marker":"{:s}"}}}}'; - strCoordPlace = geojson.format( location.longitude, location.latitude, arrAddress[1], fn.split("-")[0] ) + geojson = '{{"type":"Feature","geometry":{{"type":"Point","coordinates":[{:.'+str(precision)+'f},{:.'+str(precision)+'f}]}},"properties":{{"name":"{:s}","title":"{:s}","marker":"{:s}"}}}}'; + strCoordPlace = geojson.format( location.longitude, location.latitude, arrAddress[1], arrAddress[1], fn.split("-")[0] ) if firstline == False : print (",") else: