parent
9b360b072c
commit
ef8cb0f7a9
@ -0,0 +1,105 @@ |
||||
#!/bin/bash |
||||
# Descarga y procesa las bases de BiciMad |
||||
# Santiago Crespo 2022 |
||||
|
||||
EMAIL="xxxxx" |
||||
PASSWORD="XXXX" |
||||
|
||||
INITIALDIR=`pwd` |
||||
TMPDIR=/tmp/bicimad |
||||
|
||||
DIA=`date +%Y-%m-%d` |
||||
HORA=`date +%H-%M-%S` |
||||
DIR="$DIA-$HORA" |
||||
|
||||
mkdir -p current |
||||
|
||||
echo "$DIR" |
||||
mkdir "$DIR" |
||||
cd "$DIR" |
||||
|
||||
rm -rf $TMPDIR |
||||
mkdir -p $TMPDIR |
||||
cd $TMPDIR |
||||
|
||||
wget -nv "https://openapi.emtmadrid.es/v1/mobilitylabs/user/login/" --header="email: $EMAIL" --header="password: $PASSWORD" -O token |
||||
TOKEN=`awk -F 'accessToken": ' '{print $2}' token | awk -F '"' '{print $2}'` |
||||
|
||||
wget -nv "https://openapi.emtmadrid.es/v1/transport/bicimad/stations/" --header="accessToken: $TOKEN" -O bicimad_stations.json |
||||
|
||||
awk -F '"data":' '{print $2}' bicimad_stations.json | perl -pe 's/},/},\n/g' | perl -pe 's/{//g' | perl -pe 's/\["id"//g' > bicimad_stations.txt |
||||
|
||||
sed -i '1s/^/ "id"/' bicimad_stations.txt |
||||
|
||||
echo '<?xml version="1.0" encoding="UTF-8"?> |
||||
<osm version="0.6" upload="false" generator="'$0'">' > bicimad_stations.osm |
||||
|
||||
ID="70000230000" |
||||
|
||||
# Para el timestamp |
||||
DIA=`date +%Y-%m-%d` |
||||
HORA=`date +%H:%M:%S` |
||||
|
||||
echo "Generando listado de estaciones fuera de servicio..." |
||||
wget -nv "https://gbfs.bici.madrid/en/station_status" |
||||
wget -nv "https://gbfs.bici.madrid/en/station_information" |
||||
#grep '"is_renting":"false","is_returning":"false"' station_status | awk -F '"' '{print "\""$4"\""}' > out-of-service-stations-id |
||||
grep '"is_renting":"false","is_returning":"false"' station_status | awk -F '"' '{print $4}' > out-of-service-stations-id |
||||
|
||||
echo "Getting REF a partir del ID..." |
||||
rm -f out-of-service-stations |
||||
while IFS='' read -r line || [[ -n "$line" ]]; do |
||||
if grep -q '"station_id":"'$line'"' station_information; then |
||||
grep '"station_id":"'$line'"' station_information | awk -F '"short_name":' '{print $2}' | awk -F ',' '{print $1}' >> out-of-service-stations |
||||
fi |
||||
done < out-of-service-stations-id |
||||
|
||||
|
||||
echo "Procesando..." |
||||
# $6 = Nombre calle número |
||||
# $12 = REF |
||||
|
||||
while IFS='' read -r line || [[ -n "$line" ]]; do |
||||
NAME=`echo $line | awk -F '"' '{print $6}'` |
||||
REF=`echo $line | awk -F '"' '{print $12}'` |
||||
ADDRESS=`echo $line | awk -F '"' '{print $16}'` |
||||
CAPACITY=`echo $line | awk -F '"' '{print $23}' | awk -F ',' '{print $1}' | awk -F ' ' '{print $2}'` |
||||
COORDS=`echo $line | awk -F '[' '{print $2}' | awk -F ']' '{print $1}'` |
||||
LAT=`echo $COORDS | awk -F ',' '{print $2}' | perl -pe 's/ //g'` |
||||
LON=`echo $COORDS | awk -F ',' '{print $1}'` |
||||
|
||||
if grep -q '"'$REF'"' out-of-service-stations; then |
||||
AMENITY="disused:amenity" |
||||
else |
||||
AMENITY="amenity" |
||||
fi |
||||
|
||||
# "echo -e" para que convierta la codificación a UTF-8: Sof\u00eda -> Sofía |
||||
echo -e '<node version="1" changeset="1" timestamp="'$DIA'T'$HORA'Z" id="'$ID'" lat="'$LAT'" lon="'$LON'" visible="true"> |
||||
<tag k="'$AMENITY'" v="bicycle_rental"/> |
||||
<tag k="network" v="BiciMAD"/> |
||||
<tag k="source" v="EMT Madrid"/> |
||||
<tag k="source:date" v="'$DIA'"/> |
||||
<tag k="operator" v="Empresa Municipal de Transportes de Madrid"/> |
||||
<tag k="ref" v="'$REF'"/> |
||||
<tag k="name" v="BiciMAD '${REF^^}' - '$NAME'"/> |
||||
<tag k="addr:full" v="'$ADDRESS'"/> |
||||
<tag k="capacity" v="'$CAPACITY'"/> |
||||
</node> |
||||
' >> bicimad_stations.osm |
||||
|
||||
|
||||
ID=$((ID + 1)) |
||||
|
||||
done < bicimad_stations.txt |
||||
|
||||
OUTPUT="amenity-bicycle_rental-bicimad_stations_EMT.osm" |
||||
mkdir -p $INITIALDIR/current/ |
||||
echo '</osm>' >> bicimad_stations.osm && ascii2uni -a U -q bicimad_stations.osm > $OUTPUT && cp $OUTPUT "$INITIALDIR/$DIR/" && cp $OUTPUT "$INITIALDIR/current/" && cd "$INITIALDIR/$DIR/" && echo "$OUTPUT creado!" || exit 1 |
||||
|
||||
|
||||
date |
||||
exit 0 |
||||
|
||||
|
||||
|
Loading…
Reference in new issue