Commit 92c9e8b4 authored by Dominika Liberda's avatar Dominika Liberda 💽
Browse files

Initial;;Laura is cute :3

parents
# sdomi's PKP tools
This is a (very) work-in-progress project; Currently, there are two messy scripts:
`./platform.sh "Warszawa Centralna"` - gives links to PKP's static timetable page, usually with platforms listed
`./trains.sh "Opole Główne"` - lists trains that will stop on station in the next few hours
#!/bin/bash
stationStart=$(jq -nr --arg v "$1" '$v|@uri')
stationEnd=$(jq -nr --arg v "$2" '$v|@uri')
stationStartId=$(curl -s "https://rozklad-pkp.pl/station/search?term=$stationStart&short=false" | jq '.[0].value|tonumber')
stationEndId=$(curl -s "https://rozklad-pkp.pl/station/search?term=$stationEnd&short=false" | jq '.[0].value|tonumber')
time=$(date "+%H:%M")
date=$(date "+%d.%m.%y")
detailsUrl=$(curl -s -c cookies.txt "https://rozklad-pkp.pl/pl/tp?queryPageDisplayed=yes&REQ0JourneyStopsS0A=1&REQ0JourneyStopsS0G=$stationStartId&REQ0JourneyStopsZ0A=1&REQ0JourneyStopsZ0G=$stationEndId&date=$date&time=$time&REQ0JourneyProduct_opt_section_0_list=1:100000&start=start&came_from_form=1" | grep -Poh '<a class="do-print".*?Rozwi&#324; wszystkie' | sed -E 's/.*href="//g;s/" >.*//;s/\&amp;/\&/g;s/\&\&/\&/g;')
echo "https://rozklad-pkp.pl$detailsUrl"
echo ---
curl -s -b cookies.txt -H "Cookie: NGINX1=ngnix11; NGINX=ngnix2;" "https://rozklad-pkp.pl$detailsUrl" | grep -Poh 'trainlink.*?"' | sed -s 's/\&amp;/\&/g;s/\&\&/\&/g;s/trainlink/http\:\/\/rozklad-pkp.pl\/pl\/ti?&/g;s/&"$//g'
rm cookies.txt
#!/bin/bash
function station() {
a="$@"
s=$(jq -nr --arg v "$a" '$v|@uri')
data=$(curl -s "http://infopasazer.intercity.pl/?p=stations&q=$s")
IFS=$'\n'
links=($(echo "$data" | grep -Poh "\?p\=station\&id\=[0-9]+"))
names=($(echo "$data" | grep -i ">$@" | 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
}
station="$(station "$1")"
if [[ $(echo "$station" | grep -i "multiple") != '' ]]; then
echo "$station"
exit 0
fi
echo $station | grep -Poh "^[^:]+"
url="http://infopasazer.intercity.pl/$(echo $station | grep -Poh "^[^:]+")"
data="$(curl $url | tr -d '\r' | tr -d '\n' | grep -Poh "<tr.*?</tr>")"
IFS=$'\n'
trains=$(echo $data | grep -Poh '<a href=".*?">.*?<br/>.*?</a>')
links=($(echo $data | grep -Poh "\?p\=train&id\=[0-9]+"))
names=($(echo "$trains" | grep -Poh ">.*<br/>.*</a>" | sed -s 's/<br\/>/ /g;s/<\/a>//g;s/^>//g'))
for (( i=0; i<${#links[@]}; i++ )); do
#echo "${links[$i]} ---- ${names[$i]}"
echo ${links[$i]}: ${names[$i]}
done
# Numer pociągu | Przewoźnik | Data | Relacja | Przyjazd planowo | Opóźnienie
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment