Created
March 6, 2018 19:33
-
-
Save alogic0/01e94ec026c4eed2a48e3fa23227a881 to your computer and use it in GitHub Desktop.
hunt for opening new seats in the train
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG=~/tmp/kov-od/03-23.txt | |
P_PRE=$(tac $LOG | egrep -m 1 'Плацкарт' | egrep -o '[[:digit:]]+') | |
K_PRE=$(tac $LOG | egrep -m 1 'Купе' | egrep -o '[[:digit:]]+') | |
function show-last () { | |
echo "Купе: $K_PRE"; | |
echo "Плацкарт: $P_PRE"; | |
echo; | |
} | |
show-last; | |
while :; do | |
date | |
TMP=$(mktemp /tmp/$(basename $0)-$(date +%Y%m%d%H%M%S)-XXX) | |
TMP2=$(mktemp /tmp/$(basename $0)-$(date +%Y%m%d%H%M%S)-2-XXX) | |
wget -q -O - --post-data='from=2218020&to=2208001&date=2018-03-23&time=00%3A00&train=084%D0%9B&get_tpl=1' https://booking.uz.gov.ua/ru/mobile/train_wagons/ > $TMP | |
## tee $TMP | |
echo | |
cat $TMP | grep -Eo '"title":"[[:alpha:]]+","letter":".","free":[[:digit:]]+,"cost":[[:digit:]]+' \ | |
| cut -d ',' -f 1,3,4 | grep -v 'Люкс' | tee $TMP2 | |
P_NOW=$(cat $TMP2 | grep 'Плацкарт' | egrep -o '"free":[[:digit:]]+' | egrep -o '[[:digit:]]+') | |
P_NOW=${P_NOW:-0} | |
K_NOW=$(cat $TMP2 | grep 'Купе' | egrep -o '"free":[[:digit:]]+' | egrep -o '[[:digit:]]+') | |
K_NOW=${K_NOW:-0} | |
if [[ $K_NOW > $K_PRE ]]; then snd-sms.sh "KOV OD 03-23 Купе: $K_NOW"; fi | |
if [[ $P_NOW > $P_PRE ]]; then snd-sms.sh "KOV OD 03-23 Плацкарт: $P_NOW"; fi | |
K_PRE=$K_NOW; | |
P_PRE=$P_NOW; | |
{ date; | |
show-last; | |
} >> $LOG | |
## if [[ $(echo $(grep -Eo 'places":[[:digit:]]+' $TMP | grep -Eo '[[:digit:]]+') | sed 's/ /+/g' | bc) -gt 1 ]] | |
## then | |
## lnk=$(grep 'http:' $TMP) | |
## xdg-open "$lnk" | |
## alert-tickets.sh | |
## exit | |
## fi | |
rm $TMP $TMP2 | |
echo | |
echo Waiting 15 minutes until $(date -d '+15 min' +'%H:%M') | |
## timer-back.sh $(date -d '+15 min' +'%H:%M') | |
sleep 15m | |
done |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## Usage: $0 "08:00" | |
clr_l () { echo -ne '\e[2K\r'; } | |
now() { date +%s; } | |
THEN=$(date -d "$1" +%s) | |
left() { date -d "1980-01-01 +$(($THEN - $(now))) sec" +%H:%M:%S; } | |
while [[ $THEN -gt $(now) ]]; do | |
clr_l | |
echo -n "$(left) left until $1" | |
sleep 1 | |
done | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment