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

Initial;;Laura is cute :3

# sdomi's PKP tools
This is a (very) work-in-progress project; Currently, there are two messy scripts:
`./ "Warszawa Centralna"` - gives links to PKP's static timetable page, usually with platforms listed
`./ "Opole Główne"` - lists trains that will stop on station in the next few hours
stationStart=$(jq -nr --arg v "$1" '$v|@uri')
stationEnd=$(jq -nr --arg v "$2" '$v|@uri')
stationStartId=$(curl -s "$stationStart&short=false" | jq '.[0].value|tonumber')
stationEndId=$(curl -s "$stationEnd&short=false" | jq '.[0].value|tonumber')
time=$(date "+%H:%M")
date=$(date "+%d.%m.%y")
detailsUrl=$(curl -s -c cookies.txt "$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 "$detailsUrl"
echo ---
curl -s -b cookies.txt -H "Cookie: NGINX1=ngnix11; NGINX=ngnix2;" "$detailsUrl" | grep -Poh 'trainlink.*?"' | sed -s 's/\&amp;/\&/g;s/\&\&/\&/g;s/trainlink/http\:\/\/\/pl\/ti?&/g;s/&"$//g'
rm cookies.txt
function station() {
s=$(jq -nr --arg v "$a" '$v|@uri')
data=$(curl -s "$s")
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"
for (( i=0; i<${#links[@]}; i++ )); do
echo "${links[$i]}:${names[$i]}"
station="$(station "$1")"
if [[ $(echo "$station" | grep -i "multiple") != '' ]]; then
echo "$station"
exit 0
echo $station | grep -Poh "^[^:]+"
url="$(echo $station | grep -Poh "^[^:]+")"
data="$(curl $url | tr -d '\r' | tr -d '\n' | grep -Poh "<tr.*?</tr>")"
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]}
# 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