From c26652c3061bd187afb5e74e67c4c68c41251361 Mon Sep 17 00:00:00 2001 From: vv01f Date: Wed, 5 Jun 2019 11:40:34 +0200 Subject: [PATCH] fix for generalization and data query --- lookup.py | 19 +++++++++++++++---- prepare.sh | 2 +- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/lookup.py b/lookup.py index 7c94016..ff58945 100755 --- a/lookup.py +++ b/lookup.py @@ -2,12 +2,20 @@ from geopy import Nominatim # ~ import json +import sys +# ~ fn="ct-csv" +if len(sys.argv) == 2: + fn = sys.argv[1] +else: + print("expecting one argument: csv-file."); + print("received "+str(len(sys.argv))+" argument(s): "+str(sys.argv)); + sys.exit(1) # exit with error + +# for retreiving geo coordinates from addresses geolocator = Nominatim(user_agent="my-mapper") -# first test to retreive geo coordinates - -fn="ct-csv" +# get data from file with open( fn, 'r' ) as fp: for place in fp: #error handling: expect @@ -18,11 +26,14 @@ with open( fn, 'r' ) as fp: 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":[{:.6f}, {:.6f}]}},"properties":{{"name":"{:s}","marker":"ct"}}}}'; + geojson = '{{"type":"Feature","geometry": {{"type": "Point","coordinates":[{:.6f}, {:.6f}]}},"properties":{{"name":"{:s}","marker":fn.split("-")[0]}}}}'; strCoordPlace = geojson.format( location.latitude, location.longitude, arrAddress[3] ) # ~ {"type": "Feature","geometry": {"type": "Point","coordinates":[125.6, 10.1]},"properties":{"name":"Dinagat Islands"}} print ( strCoordPlace ) +# exit fine +sys.exit(0) + # ~ m = folium.Map( # etc..) # ~ m.save("filename.png") diff --git a/prepare.sh b/prepare.sh index 96db905..ab5ee5e 100755 --- a/prepare.sh +++ b/prepare.sh @@ -8,7 +8,7 @@ test -e baerer && auth=$(head -1 baerer) || { #~ test -e ct-json && echo "file already exists." || curl -o ct-json "https://"${auth}"doku.ccc.de/Spezial:Semantische_Suche/-5B-5BKategorie:Chaostreffs-5D-5D-20-5B-5BChaostreff-2DIs-2DErfa::falsch-5D-5D-20-5B-5BChaostreff-2DActive::wahr-5D-5D/-3FChaostreff-2DPhysical-2DAddress%3DAdresse/-3FChaostreff-2DPhysical-2DPostcode%3DPLZ/-3FChaostreff-2DPhysical-2DCity%3DStadt/-3FChaostreff-2DCountry%3DLand/mainlabel%3D/limit%3D100/order%3DASC/sort%3DErfa-2DCity/offset%3D0/format%3Djson/headers%3Dshow/searchlabel%3DJSON" #~ test -e erfa-json && echo "file already exists." || curl -o erfa-json "https://"${auth}"doku.ccc.de/Spezial:Semantische_Suche/-5B-5BKategorie:Chaostreffs-5D-5D-20-5B-5BChaostreff-2DIs-2DErfa::wahr-5D-5D-20-5B-5BChaostreff-2DActive::wahr-5D-5D/-3FChaostreff-2DPhysical-2DAddress%3DAdresse/-3FChaostreff-2DPhysical-2DPostcode%3DPLZ/-3FChaostreff-2DPhysical-2DCity%3DStadt/-3FChaostreff-2DCountry%3DLand/mainlabel%3D/limit%3D100/order%3DASC/sort%3DErfa-2DCity/offset%3D0/format%3Djson/headers%3Dshow/searchlabel%3DJSON" test -e ct-csv && echo "file already exists." || curl -o ct-csv "https://"${auth}"doku.ccc.de/Spezial:Semantische_Suche/-5B-5BKategorie:Chaostreffs-5D-5D-20-5B-5BChaostreff-2DIs-2DErfa::falsch-5D-5D-20-5B-5BChaostreff-2DActive::wahr-5D-5D/-3FChaostreff-2DPhysical-2DAddress%3DAdresse/-3FChaostreff-2DPhysical-2DPostcode%3DPLZ/-3FChaostreff-2DPhysical-2DCity%3DStadt/-3FChaostreff-2DCountry%3DLand/mainlabel%3D/limit%3D100/order%3DASC/sort%3DErfa-2DCity/offset%3D0/format%3Dcsv/headers%3Dshow/searchlabel%3DCSV/sep%3D,/filename%3Dct-2Dbesuchsadressen.csv" -test -e erfa-csv && echo "file already exists." || curl -o erfa-csv "https://"${auth}"doku.ccc.de/Spezial:Semantische_Suche/-5B-5BKategorie:Chaostreffs-5D-5D-20-5B-5BChaostreff-2DIs-2DErfa::wahr-5D-5D-20-5B-5BChaostreff-2DActive::wahr-5D-5D/-3FChaostreff-2DPhysical-2DAddress%3DAdresse/-3FChaostreff-2DPhysical-2DPostcode%3DPLZ/-3FChaostreff-2DPhysical-2DCity%3DStadt/-3FChaostreff-2DCountry%3DLand/mainlabel%3D/limit%3D100/order%3DASC/sort%3DErfa-2DCity/offset%3D0/format%3Dcsv/headers%3Dshow/searchlabel%3DCSV/sep%3D,/filename%3Derfa-2Dbesuchsadressen.csv" +test -e erfa-csv && echo "file already exists." || curl -o erfa-csv "https://"${auth}"doku.ccc.de/Spezial:Semantische_Suche/-5B-5BKategorie:Erfa-2DKreise-5D-5D-20-5B-5BChaostreff-2DActive::wahr-5D-5D/-3FChaostreff-2DPhysical-2DAddress%3DAdresse/-3FChaostreff-2DPhysical-2DPostcode%3DPLZ/-3FChaostreff-2DPhysical-2DCity%3DStadt/-3FChaostreff-2DCountry%3DLand/mainlabel%3D/limit%3D100/order%3DASC/sort%3DErfa-2DCity/offset%3D0/format%3Dcsv/headers%3Dshow/searchlabel%3DCSV/sep%3D,/filename%3Derfa-2Dbesuchsadressen.csv" # preprocess csv data for file in $(echo 'ct-csv\nerfa-csv'); do sed -e 's/"//g' ${file} > tmpfile && mv tmpfile ${file}