From 92c9e8b4541180d8c531b2b27acf117b5f84077a Mon Sep 17 00:00:00 2001 From: Dominika Date: Sun, 6 Sep 2020 23:39:27 +0200 Subject: [PATCH] Initial;;Laura is cute :3 --- README.md | 7 +++++++ platform.sh | 20 ++++++++++++++++++++ trains.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+) create mode 100644 README.md create mode 100755 platform.sh create mode 100755 trains.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..e59b401 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# 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 diff --git a/platform.sh b/platform.sh new file mode 100755 index 0000000..590181b --- /dev/null +++ b/platform.sh @@ -0,0 +1,20 @@ +#!/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 '.*//;s/\&/\&/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/\&/\&/g;s/\&\&/\&/g;s/trainlink/http\:\/\/rozklad-pkp.pl\/pl\/ti?&/g;s/&"$//g' +rm cookies.txt diff --git a/trains.sh b/trains.sh new file mode 100755 index 0000000..150c3c6 --- /dev/null +++ b/trains.sh @@ -0,0 +1,42 @@ +#!/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///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 "")" + +IFS=$'\n' +trains=$(echo $data | grep -Poh '.*?
.*?
') + + +links=($(echo $data | grep -Poh "\?p\=train&id\=[0-9]+")) +names=($(echo "$trains" | grep -Poh ">.*
.*" | sed -s 's// /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