Skip to content

Instantly share code, notes, and snippets.

@ASafaeirad
Last active October 25, 2023 17:03
Show Gist options
  • Select an option

  • Save ASafaeirad/3e0d89555a26f9bc20c88271defe8ec3 to your computer and use it in GitHub Desktop.

Select an option

Save ASafaeirad/3e0d89555a26f9bc20c88271defe8ec3 to your computer and use it in GitHub Desktop.
Retrieve available appointment dates for municipalities in Utrecht

This script retrieves available appointment dates for municipalities in Utrecht.

Prerequisites

bun

Usage:

schedules [month] [year]

examples:
  schedules - shows the available days for current month of the current year
  schedules 10 - shows the available days for Oct of the current year
  schedules 1 2024 - shows the available days for Jan 2024
#!/usr/bin/env -S bunx zx
$.verbose = false
const date = new Date()
const branch = '6799b9a23eb23e3be8cff82b78da95d10503b9057b8cf48bc34c4bc47f0'
const month = process.argv[3] ? process.argv[3] - 1 : date.getMonth()
const year = process.argv[4] ?? date.getFullYear()
function getMonthName() {
return new Date(2000, month, 1)
.toLocaleString('default', { month: 'long' })
}
console.log(
`Displaying available days in "${getMonthName()} ${date.getFullYear()}"`
)
const { stdout } = await $`
curl \
'https://afspraak.utrecht.nl/qmaticwebbooking/rest/schedule/branches/${branch}/dates;servicePublicId=2d7f771f9554b048625e837f7f0c8936b1993136558d7625d59c48846473c44d;customSlotLength=25' \
-H 'authority: afspraak.utrecht.nl' \
-H 'accept: application/json, text/plain, */*'`
const data = JSON.parse(stdout)
const days = data
.map(d => new Date(d.date))
.filter(d => d.getMonth() === month)
.map(d => d.toLocaleDateString('en-UK'))
.join('\n')
console.log();
console.log(days || 'No days are available.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment