Skip to content

Instantly share code, notes, and snippets.

@vierbergenlars
Created July 29, 2019 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vierbergenlars/87200d71ddeef228c4952b60a87a7ca8 to your computer and use it in GitHub Desktop.
Save vierbergenlars/87200d71ddeef228c4952b60a87a7ca8 to your computer and use it in GitHub Desktop.
#!/bin/bash -e
data="$(curl -A "delay-notification/1.0 (irail@vbgn.be)" https://api.irail.be/connections/\?from\=$IRAIL_FROM\&to\=$IRAIL_TO\&format\=json\&time=$IRAIL_TIME)"
connection="$(echo "$data" | jq '[.connection[] | select(has("vias") == false and .departure.left == "0")][0]')" # First one that goes straight through and has not left
delay="$[ $(echo "$connection" | jq '.departure.delay' -r) / 60 ]"
train_id="$(echo "$connection" | jq '.departure.vehicle' -r)"
departure_time_unix="$(echo "$connection" | jq '(.departure.delay|tonumber) + (.departure.time|tonumber)' -r)"
departure_time="$(date --date=@$departure_time_unix +%R)"
canceled="$(echo "$connection" | jq '.departure.canceled' -r)"
if [[ "$canceled" == "1" ]]; then
curl -X POST https://maker.ifttt.com/trigger/$IFTTT_TRIGGER/with/key/$IFTTT_KEY -d "{\"value1\": \"Train cancelled\", \"value2\": \"Cancelled $train_id @ $departure_time\"}" -H 'Content-Type: application/json'
fi
# /etc/systemd/system/nmbs-updates.service
[Service]
Type=oneshot
ExecStart=/usr/local/bin/nmbs-updates
User=lars
# /etc/systemd/system/nmbs-updates.timer
[Unit]
Description=Run nmbs-updates on weekdays
[Install]
WantedBy=timers.target
[Timer]
OnCalendar=Mon..Fri 06:00
OnCalendar=Mon..Fri 06:15
OnCalendar=Mon..Fri 06:30
OnCalendar=Mon..Fri 06:45
OnCalendar=Mon..Fri 06:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment