summaryrefslogtreecommitdiff
path: root/bin/wiki/Scripts/CompletaDireccionPorGeo.sh
blob: c77e83f3d778d655a7feb623a6787f74f9fc69af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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"