67 lines
1.7 KiB
Bash
67 lines
1.7 KiB
Bash
#!/bin/bash
|
|
function getStations() {
|
|
a="$@"
|
|
s=$(jq -nr --arg v "$a" '$v|@uri')
|
|
data=$(curl -s "http://infopasazer.intercity.pl/?p=stations&q=$s")
|
|
IFS=$'\n'
|
|
links=($(grep -Poh "\?p\=station\&id\=[0-9]+" <<< "$data"))
|
|
names=($(grep -i ">$@" <<< "$data" | tr -d '\r' | sed -s 's/<span class="">//g;s/ //g;s/<\/span>//g'))
|
|
|
|
if [[ ${#links[@]} -gt 1 ]]; then
|
|
echo "Multiple stations found! Narrow your search down, pretty please"
|
|
fi
|
|
|
|
for (( i=0; i<${#links[@]}; i++ )); do
|
|
echo "${links[$i]}:${names[$i]}"
|
|
done
|
|
}
|
|
|
|
function getTrains() {
|
|
url="http://infopasazer.intercity.pl/$(grep -Poh "^[^:]+" <<< $1)"
|
|
data="$(curl -s $url | tr -d '\r' | tr -d '\n' | grep -Poh "<tr.*?</tr>")"
|
|
|
|
IFS=$'\n'
|
|
trains=$(grep -Poh '<a href=".*?">.*?<br/>.*?</a>' <<< "$data")
|
|
links=($(grep -Poh "\?p\=train&id\=[0-9]+" <<< "$data"))
|
|
names=($(grep -Poh ">.*<br/>.*</a>" <<< "$trains" | sed -s 's/<br\/>/ /g;s/<\/a>//g;s/^>//g'))
|
|
}
|
|
|
|
function getTrainInfo() {
|
|
IFS=$'\n'
|
|
|
|
res=($(curl -s "http://infopasazer.intercity.pl/?p=train&id=$1" | tr -d '\n\r' | sed -E 's/ //g' | grep -Poh '<tr class="_TableDelayCol.*?</tr>'))
|
|
unset IFS
|
|
}
|
|
|
|
function parseStationInfo() {
|
|
IFS=$'\n'
|
|
|
|
local -n _station=$2
|
|
|
|
uwu=($(grep -Poh '<td class="Col".*?</td>' <<< "$1" | grep -Poh 'span.*?</s' | sed -E 's@</a.*@@;s/.*>//;s/<\/s//'))
|
|
|
|
_station[train_number]=${uwu[0]}
|
|
_station[date]=${uwu[1]}
|
|
_station[relation]=${uwu[2]}
|
|
_station[name]=${uwu[3]}
|
|
_station[arrival]=${uwu[4]}
|
|
_station[arrival_delay]=${uwu[5]}
|
|
_station[departure]=${uwu[6]}
|
|
_station[departure_delay]=${uwu[7]}
|
|
|
|
unset IFS
|
|
}
|
|
|
|
function getCurrentStation() {
|
|
IFS=$'\n';
|
|
local -n _dat=$1
|
|
local -n _res=$2
|
|
|
|
for (( i=0; i<${#_dat[@]}; i++ )); do
|
|
if [[ "$(grep current <<< "${_dat[$i]}")" != '' ]]; then
|
|
_res=$i
|
|
break
|
|
fi
|
|
done
|
|
}
|