Skip to content

Commit

Permalink
Added tentative parsing of active day query response text
Browse files Browse the repository at this point in the history
  • Loading branch information
pfurbacher committed Mar 9, 2021
1 parent de55381 commit d4f9239
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions site-scrapers/TrinityEMS/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ async function getDailyAvailabilityCountsForMonth(page) {
return monthlyAvailability;
}

/** Looks for "no-dates-available" class, or ".activeday" elements.
/**
* Looks for "no-dates-available" class, or ".activeday" elements.
* If not found, there are active days, and the page should be
* parsed for which days have availability.
*
Expand All @@ -139,6 +140,9 @@ async function getActiveDays(page) {
}

/**
* Fetches the small snippet of HTML which would appear in a popup when an active day is clicked by a human.
*
* As yet, it's not know how the slot count will be presented. See parseHTMLforSlotCount().
*
* @param {*} page
* @param {String} dateStr -- yyyy-mm-dd, as in '2021-04-26'
Expand All @@ -158,7 +162,8 @@ async function getSlotsForDate(page, dateStr) {

return await page.evaluate(async (url) => {
const response = await fetch(url);
return await response.text();
const text = await response.text();
return parseHTMLforSlotCount(text);
}, url);
}

Expand Down Expand Up @@ -212,6 +217,19 @@ function accumulateAvailabilityForMonth(dailySlotsForMonth) {
}
}

/**
* TODO: this is just a guess as to how the popup will present the number of appointments.
*
* @param {String} responseText
*/
function parseHTMLforSlotCount(responseText) {
const text = responseText;
const pattern = /\d+/;
const number = text.match(pattern);

return number == null ? 0 : number[0];
}

async function waitForLoadComplete(page, loaderSelector) {
await page.waitForSelector(loaderSelector, {
visible: true,
Expand Down

0 comments on commit d4f9239

Please sign in to comment.