#!/bin/bash # PKP.sh - common script housing all pkp-tools functions # ./pkp.sh (platform|stops|trains) source func.sh # trains if [[ $1 == "trains" ]]; then station="$(getStations "$2")" if [[ $(echo "$station" | grep -i "multiple") != '' ]]; then echo "$station" exit 0 fi echo $station | grep -Poh "^[^:]+" getTrains $station for (( i=0; i<${#links[@]}; i++ )); do echo ${links[$i]}: ${names[$i]} done fi if [[ $1 == "stops" ]]; then commonStations=(60608 33605 73312 7500 62653 273 30601 80416 27805 46409 60103 24000) # 60608 - opole główne # 33605 - Warszawa Centralna # 73312 - Katowice # 24000 - Białystok # 7500 - Gdańsk Główny # 62653 - Częstochowa # 273 - Szczecin # 30601 - Poznań # 80416 - Krk # 19703 - Toruń # 27805 - Zielona Góra # 46409 - Łódź Widzew # 60103 - Wrocław for i in ${commonStations[@]}; do getTrains "?p=station&id=$i" for (( i=0; i<${#links[@]}; i++ )); do echo ${links[$i]}: ${names[$i]} done done fi if [[ $1 == "platform" ]]; then stationStart=$(jq -nr --arg v "$2" '$v|@uri') stationEnd=$(jq -nr --arg v "$3" '$v|@uri') if [[ "$4" == "" ]]; then time=$(date "+%H:%M") else time=$(date --date "$4" "+%H:%M") fi if [[ "$5" == "" ]]; then date=$(date "+%d.%m.%y") else date=$(date --date "$5" "+%d.%m.%y") fi 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') detailsUrl=$(curl -s -c /tmp/cookiemonster.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 '.*//;s/\&/\&/g;s/\&\&/\&/g;') echo "https://rozklad-pkp.pl$detailsUrl" echo --- curl -s -b /tmp/cookiemonster.txt "https://rozklad-pkp.pl$detailsUrl" | grep -Poh 'trainlink.*?"' | sed -s 's/\&/\&/g;s/\&\&/\&/g;s/trainlink/http\:\/\/rozklad-pkp.pl\/pl\/ti?&/g;s/&"$//g' rm /tmp/cookiemonster.txt fi