add script
This commit is contained in:
parent
7dac26d46b
commit
a5919a902c
|
@ -0,0 +1,83 @@
|
|||
#!/bin/bash
|
||||
|
||||
if ! ping -q -c1 chch.it>/dev/null;
|
||||
then
|
||||
echo "no connection to the internet"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
STATIONS[0]="18"
|
||||
STATIONS[1]="202"
|
||||
STANAME=()
|
||||
|
||||
NUMOFSTA=${#STATIONS[*]}
|
||||
|
||||
FOO=$(curl --connect-timeout 5 -s "http://www.cvag.de/eza/mis/stations?minLat=0&maxLat=100&minLon=0&maxLon=100")
|
||||
for ((i=0; i<${#STATIONS[*]}; i++))
|
||||
do
|
||||
case ${STATIONS[$i]} in
|
||||
''|*[!0-9]*)
|
||||
STANAME[$i]=$(echo -n "$FOO" | jq -r '.stations | .[] | select(.displayName | contains("'"${STATIONS[$i]}"'")) | .number')
|
||||
;;
|
||||
|
||||
*)
|
||||
STANAME[$i]=$(echo -n "$FOO" | jq -r '.stations | .[] | select(.number | contains('"${STATIONS[$i]}"')) | .displayName')
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
MYOUTPUT=""
|
||||
for ((j=0; j<"$NUMOFSTA"; j++))
|
||||
do
|
||||
FOO=$(curl --connect-timeout 5 -s http://cvag.de/eza/mis/stops/station/CAG-${STATIONS[$j]})
|
||||
BAR=$FOO
|
||||
|
||||
FOO=$(echo "$FOO" | jq -r ".stops | .[]")
|
||||
BAR=$(echo "$BAR" | jq -r ".now")
|
||||
|
||||
# ohne dieses IFS trennt BASH an Space und erstellt damit zu viele Array-Felder
|
||||
IFS='
|
||||
'
|
||||
DESTINATIONS=($(echo -n "$FOO" | jq -r '.destination'));
|
||||
LINES=($(echo -n "$FOO" | jq -r '.line'))
|
||||
ACDEPS=($(echo -n "$FOO" | jq -r '.actualDeparture'))
|
||||
LINECOUNT=${#LINES[*]}
|
||||
|
||||
MYOUTPUT="$MYOUTPUT"'\t+--------------------+\n\t| '"${STANAME[$j]}"'|\n\t+--------------------+-----+-------------------------------+\n'
|
||||
for ((i=0; i<"$LINECOUNT"; i++))
|
||||
do
|
||||
MILLIS=$(expr "${ACDEPS[$i]}" - "$BAR")
|
||||
SEKS=$(expr "$MILLIS" / 1000)
|
||||
MILLIS=$(expr "$MILLIS" % 1000)
|
||||
MINS=$(expr "$SEKS" / 60)
|
||||
SEKS=$(expr "$SEKS" % 60)
|
||||
MINSSPACE=""
|
||||
SEKSSPACE=""
|
||||
MILLISSPACE=""
|
||||
if [ "$MINS" -lt 100 ]
|
||||
then
|
||||
MINSSPACE=" "
|
||||
fi
|
||||
if [ "$MINS" -lt 10 ]
|
||||
then
|
||||
MINSSPACE=" "
|
||||
fi
|
||||
if [ "$SEKS" -lt 10 ]
|
||||
then
|
||||
SEKSSPACE=" "
|
||||
fi
|
||||
if [ "$MILLIS" -lt 100 ]
|
||||
then
|
||||
MILLISSPACE=" "
|
||||
fi
|
||||
if [ "$MILLIS" -lt 10 ]
|
||||
then
|
||||
MILLISSPACE=" "
|
||||
fi
|
||||
MYOUTPUT="$MYOUTPUT""\t|${MINSSPACE}${MINS} min ${SEKSSPACE}${SEKS} s ${MILLISSPACE}${MILLIS} ms | ${LINES[$i]} | ${DESTINATIONS[$i]} |\n"
|
||||
done
|
||||
MYOUTPUT="$MYOUTPUT"'\t+--------------------+-----+-------------------------------+\n'
|
||||
MYOUTPUT="$MYOUTPUT"' \n'
|
||||
MYOUTPUT="$MYOUTPUT"' \n'
|
||||
done
|
||||
echo -e "$MYOUTPUT"
|
Loading…
Reference in New Issue