summaryrefslogtreecommitdiff
path: root/bin/wiki/Scripts/CompletaDireccionPorGeo.sh
diff options
context:
space:
mode:
Diffstat (limited to 'bin/wiki/Scripts/CompletaDireccionPorGeo.sh')
-rwxr-xr-xbin/wiki/Scripts/CompletaDireccionPorGeo.sh35
1 files changed, 35 insertions, 0 deletions
diff --git a/bin/wiki/Scripts/CompletaDireccionPorGeo.sh b/bin/wiki/Scripts/CompletaDireccionPorGeo.sh
new file mode 100755
index 00000000..c77e83f3
--- /dev/null
+++ b/bin/wiki/Scripts/CompletaDireccionPorGeo.sh
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+# Este script lo usamos para actualizar los datos de ubicacion de experiencia a partir del campo que tiene la geolocalizacion... algo asi como "reverse geocoding". Usamos OSM nominatim: https://nominatim.org/release-docs/develop/api/Search/
+#
+# Se puede usar como: for i in `php ../ListarPaginas.php Plantilla:Experiencia`; do ./CompletaDireccionPorGeo.sh "$i"; done
+
+EXP="$1"
+
+curl -s "https://nominatim.openstreetmap.org/search.php?format=json&addressdetails=1&q=`php ../PropiedadObtener.php -t="$EXP" -p="experiencia:lugar" | sed 's/, /%2C+/g'`" > /tmp/json
+
+CALLE_ORIG=`php ../PropiedadObtener.php -t="$EXP" -p="experiencia:lugar-calle"`
+
+cat /tmp/json | jq .
+
+CALLE=`cat /tmp/json | jq '.[] | .address.road' && cat /tmp/json | jq '.[] | .address.house_number' && echo ", " && cat /tmp/json | jq '.[] | .address.neighbourhood' && echo ", " && cat /tmp/json | jq '.[] | .address.suburb'`
+CIUDAD=`cat /tmp/json | jq '.[] | .address.city' && cat /tmp/json | jq '.[] | .address.town' && echo ", " && cat /tmp/json | jq '.[] | .address.state_district'`
+PROVINCIA=`cat /tmp/json | jq '.[] | .address.state'`
+PAIS=`cat /tmp/json | jq '.[] | .address.country_code'`
+
+# Correcciones finales de formato
+
+if [ -z "$CALLE_ORIG" ]
+then
+ CALLE=`echo $CALLE | sed 's/"//g' | sed 's/ ,/,/g' | sed 's/null//g' | sed 's/ , //g' `
+ # No hay calle
+else
+ CALLE=`echo $CALLE | sed 's/"//g' | sed 's/ ,/,/g' | sed 's/null//g' | sed 's/ , //g' `
+ CALLE="$CALLE_ORIG ($CALLE)"
+fi
+
+CIUDAD=`echo $CIUDAD | sed 's/"//g' | sed 's/ ,/,/g' | sed 's/null//g' | sed 's/ , //g' `
+PROVINCIA=`echo $PROVINCIA | sed 's/"//g' | sed 's/ ,/,/g' | sed 's/null//g' | sed 's/ , //g' `
+PAIS=`echo ${PAIS^^} | sed 's/"//g' | sed 's/null//g'`
+
+php ../PropiedadActualizar.php -t="$EXP" -f="true" -p="experiencia:lugar-calle|$CALLE" -p="experiencia:lugar-ciudad|$CIUDAD" -p="experiencia:lugar-provincia|$PROVINCIA" -p="experiencia:lugar-pais|$PAIS"