Last active
June 21, 2019 11:44
-
-
Save phenomnomnominal/6f30a009d3fde3d31942581e36e891c5 to your computer and use it in GitHub Desktop.
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
const request = require('request').defaults({ jar: true}); | |
const LOCATIONS = { /* ... */ }; | |
const PAGE_REGEXP = /(\d+-\d+)\.IBehaviorListener/; | |
const URL_ROOT = 'https://www.migrationsverket.se/ansokanbokning/'; | |
function getAppointmentsForLocation (location) { | |
const bookingPageUrl = `valjtyp?sprak=en&bokningstyp=2&enhet=${LOCATIONS[location]}&sokande=1`; | |
request(`${URL_ROOT}${bookingPageUrl}`, (_, _, body) => { | |
const [, page] = body.match(PAGE_REGEXP); | |
// ... Date stuff | |
const appointmentsUrl = `wicket/page?${page}.IBehaviorListener.1-form-kalender-kalender&start=${start}&end=${end}`; | |
request(appointmentsUrl, (_, _, body) => { | |
const appointments = JSON.parse(body); | |
appointments.forEach(appointment => { | |
console.log(`🇸🇪💉 Available appointment in ${location} at ${new Date(appointment.start)}!`); | |
}); | |
}); | |
}); | |
} | |
getAppointmentsForLocation(LOCATIONS.STOCKHOLM); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment