Skip to content

Instantly share code, notes, and snippets.

@KubqoA
Last active March 8, 2021 16:55
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 KubqoA/0991f31681a7125b2ba41296800588c9 to your computer and use it in GitHub Desktop.
Save KubqoA/0991f31681a7125b2ba41296800588c9 to your computer and use it in GitHub Desktop.
Automatic checker of available places for vaccination.

Requirements

  • curl
  • jq
  • libnotify (notify-send)

Usage

The script requires a regex to match the hospital's title, as specified in jq's documentation

For example to match all hospitals that have Bratislava or Košice in their title you can use:

./vaccination.sh "Bratislava|Košice"
[Unit]
Description=Vaccination availability checker
[Service]
ExecStart=vaccination.sh "Bratislava|Košice"
#!/bin/sh
if [ -z "$1" ]; then
echo "You must specify the hospital names regex"
exit 1
fi
echo "Querying the API"
places=$(curl -sS "https://mojeezdravie.nczisk.sk/api/v1/web/get_all_drivein_times_vacc" | jq -r ".payload[] | select(.title | test(\"$1\")) | {title: .title, capacity: (reduce .calendar_data[] as \$item (0; . + \$item.free_capacity))} | select (.capacity > 0) | \"Voľné miesta v \(.title)|Dostupná kapacita \(.capacity)\"")
count=$(if [ -z "$places" ]; then printf '%s\n' '0'; else printf '%s\n' "${places%'\n'}" | wc -l; fi)
echo "Found $count available vaccination sites"
echo "$places" |
while IFS= read -r line; do
summary=$(echo "$line" | cut -d"|" -f 1)
body=$(echo "$line" | cut -d"|" -f 2)
notify-send -u critical -t 0 "$summary" "$body" 2>/dev/null
done
exit 0
[Unit]
Description=Vaccination availability checker
[Timer]
OnCalendar=Mon-Sun *-*-* *:*:00
Persistent=true
Unit=vaccination.service
[Install]
WantedBy=timers.target
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment