Skip to content

Instantly share code, notes, and snippets.

@phenomnomnominal
Last active June 21, 2019 11:44
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 phenomnomnominal/6f30a009d3fde3d31942581e36e891c5 to your computer and use it in GitHub Desktop.
Save phenomnomnominal/6f30a009d3fde3d31942581e36e891c5 to your computer and use it in GitHub Desktop.
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