Skip to content

Commit

Permalink
Miq fix (#75)
Browse files Browse the repository at this point in the history
* Fix for recent MIQ changes

* fix date find
  • Loading branch information
alexDrinkwater authored Jul 23, 2021
1 parent 5966bb7 commit f353ac8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
22 changes: 11 additions & 11 deletions MIQ-Booking-Assistance/miq-assistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ function start(window, ipcMain) {
}
}
}
updateElectronStatus('status', 'Found "Secure your allocation" page! Wait for beep sound, then select date and continue booking.')
console.log('Found "Secure your allocation" page! Wait for beep sound, then select date and continue booking.')
updateElectronStatus('status', 'Found "Secure your allocation" page! Wait for beep sound, confirm the date selected is what you want, then do the reCAPTCHA and click \'next\' to continue booking.')
console.log('Found "Secure your allocation" page! Wait for beep sound, confirm the date selected is what you want, then do the reCAPTCHA and click \'next\' to continue booking.')
while (true) {
await prepareAndCheckPage(page)
while(true) {
Expand All @@ -90,11 +90,7 @@ function start(window, ipcMain) {
break;
}
}

}



})();
}

Expand All @@ -110,7 +106,7 @@ async function login(page) {
}

async function prepareAndCheckPage(page) {
await page.waitForSelector('.flatpickr-input');
await page.waitForSelector('#accommodation-calendar', {visible: true});

if (await findAvailability(page)) {
const status = "AVAILABLE! Found at: " + new Date().toLocaleString();
Expand Down Expand Up @@ -139,15 +135,19 @@ async function findAvailability(page) {
const fp = calendarElem._flatpickr;
if (testDates && testDates.length > 0 && checkedCount > 2) {
fp.config.enable = testDates;
calendarElem.setAttribute('data-arrival-dates', testDates.join("_"));
}
calendarElem.scrollIntoView();

const dataArrivalDates = calendarElem.getAttribute('data-arrival-dates');
const availableDates = dataArrivalDates.split('_');
const dataArrivalDates = fp?.config?.enable;
if (!dataArrivalDates || typeof dataArrivalDates[0] === 'function' || dataArrivalDates.length <= 0 ){
return false;
}

const availableDates = dataArrivalDates.map(d => d.toISOString().split('T')[0]);
const matchingDates = availableDates.filter(d => myDates.indexOf(d) !== -1);
const myMonths = [...new Set(myDates.filter(d => d.split('-').length === 2).map(d => d.split('-')[1]))].sort();
const matchingMonths = availableDates.filter(d => myMonths.indexOf(d.split('-')[1]) > -1)
const matchingMonths = availableDates.filter(d => myMonths.indexOf(d.split('-')[1]) > -1);

if (matchingDates.length > 0 || matchingMonths.length > 0 || (findAnyDate && availableDates[0])) {
const month = (findAnyDate ? availableDates[0] : matchingDates[0] || matchingMonths[0]).split('-')[1] - 1;
fp.changeMonth(month, false);
Expand Down
2 changes: 1 addition & 1 deletion MIQ-Booking-Assistance/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "miq-nz-booking-assistance",
"version": "0.10.1",
"version": "0.10.2",
"description": "A tool to help you book MIQ",
"main": "main.js",
"scripts": {
Expand Down

0 comments on commit f353ac8

Please sign in to comment.