summaryrefslogtreecommitdiff
path: root/bin/reevotech/CompletaGeoPorDireccion.sh
blob: ab87018de71ddf606431115b4bb7a6394b5ac07c (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
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

# Este script lo usamos para actualizar los datos de geolocalizcion ubicacion de experiencia a partir de los campos que contienen la dirección postal... Usamos OSM nominatim: `https://nominatim.org/release-docs/develop/api/Search/`
#
# Se puede usar como: IFS=$(echo -en "\n\b") && for i in `php ../ListarPaginas.php Plantilla:Experiencia`; do ./CompletaGeoPorDireccion.sh ecoversities "$i"; done

if [ $# -eq 0 ]
  then
    echo "Missing parameters. Use: ./bin/reevotech/CompletaGeoPorDireccion.sh deployment Endorser:XXX Endorser"
    exit
fi

DEPLOY="$1"
EXP="$2"
TEMPLATE="$3"
DATA=`php PropiedadObtener.php -d="$DEPLOY" -t="$EXP" -p="$TEMPLATE:place-street" -p="$TEMPLATE:place-city" -p="$TEMPLATE:place-state" -p="$DEPLOY:place-country" > /tmp/x && sed 's/ /+/g' /tmp/x | sed ':a;N;$!ba;s/\n/,/g'`
echo "https://nominatim.openstreetmap.org/search.php?format=json&addressdetails=1&q=$DATA"

if [ -z "$DATA" ]
then
      echo "\$DATA is empty, exiting...."
      exit
else
      echo "\$DATA is NOT empty"
fi



curl -s "https://nominatim.openstreetmap.org/search.php?format=json&addressdetails=1&q=$DATA"  > /tmp/json

cat /tmp/json | jq '.[0]'

LAT=`cat /tmp/json | jq '.[0] | .lat' | sed 's/"//g'`
LON=`cat /tmp/json | jq '.[0] | .lon' | sed 's/"//g'`

echo "Lat: $LAT"
echo "Lon: $LON"

if [ $LAT != "null" ]; then
  php PropiedadActualizar.php -d="$DEPLOY" -t="$EXP" -f="true" -p="$TEMPLATE:place|$LAT, $LON"
  sed -i "/$EXP/d" todos.log
  echo $EXP >> correctos.log
else
  echo "I was unable to get a coordinate, logging to revisar.log"
  sed -i "/$EXP/d" todos.log
  echo $EXP >> revisar.log
fi