Skip to content

Commit

Permalink
Fixes for MIQ website update (#48)
Browse files Browse the repository at this point in the history
* Fixes for MIQ website update

* fix renderer.js

* Fixed month matching and added selecting date
  • Loading branch information
alexDrinkwater committed Jul 20, 2021
1 parent 34bccd8 commit d803a18
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 45 deletions.
13 changes: 0 additions & 13 deletions MIQ-Booking-Assistance/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,6 @@ <h3>Settings:</h3>
</div>
</div>
<div>
<br/>
<label for="roomType">Room Type:</label>
<select name="roomType" id="roomType">
<option value="double">Double</option>
<option value="twin">Twin Share</option>
</select>

<p>Accessibility Room:</p>
<input type="radio" id="accessibilityRoom_yes" name="accessibilityRoom">
<label for="accessibilityRoom_yes">Yes</label><br>
<input type="radio" id="accessibilityRoom_no" name="accessibilityRoom" checked>
<label for="accessibilityRoom_no">No</label><br>

<br/>
<label for="refresh">Page Refresh Time (s):</label>
<input type="number" id="refresh" value="5">
Expand Down
29 changes: 7 additions & 22 deletions MIQ-Booking-Assistance/miq-assistance.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function start(window, ipcMain) {
await page.goto('https://allocation.miq.govt.nz/portal/dashboard');
while (true) {
await page.waitForTimeout(300);
if (page.url().includes('/event/MIQ-DEFAULT-EVENT/accommodation')) {
if (page.url().includes('/event/MIQ-DEFAULT-EVENT/accommodation/arrival-date')) {
break
}
}
Expand All @@ -84,7 +84,7 @@ function start(window, ipcMain) {
// Wait for the reset button to be pressed.
updateElectronAvailable();
await page.waitForTimeout(300);
if (page.url().includes('/event/MIQ-DEFAULT-EVENT/accommodation') && reset) {
if (page.url().includes('/event/MIQ-DEFAULT-EVENT/accommodation/arrival-date') && reset) {
reset = false;
await page.reload({ waitUntil: ["networkidle0", "domcontentloaded"] });
break;
Expand All @@ -110,22 +110,6 @@ async function login(page) {
}

async function prepareAndCheckPage(page) {
//accessibility requirement
await page.waitForSelector('#form_rooms_0_accessibilityRequirement_1');
page.$eval('#form_rooms_0_accessibilityRequirement_' + (accessibilityRequirement ? 0 : 1), elem => {
elem.checked = true;
});

page.$eval('#form_rooms_0_room', (elem, roomType) => {
switch (roomType){
case 'twin':
elem.value = 'Twin share';
break;
default:
elem.value = 'Double';
}
}, roomType);

await page.waitForSelector('.flatpickr-input');

if (await findAvailability(page)) {
Expand Down Expand Up @@ -163,11 +147,12 @@ async function findAvailability(page) {
const availableDates = dataArrivalDates.split('_');
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]))
if (matchingDates.length > 0 || matchingMonths.length > 1 || (findAnyDate && availableDates[0])) {
const month = (findAnyDate ? availableDates[0] : matchingDates[0]).split('-')[1] - 1;
fp.changeMonth(month, false)
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);
beep()
fp.setDate(matchingDates[0] || matchingMonths[0] || availableDates[0], true);
return true;
}

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.0",
"version": "0.10.1",
"description": "A tool to help you book MIQ",
"main": "main.js",
"scripts": {
Expand Down
9 changes: 0 additions & 9 deletions MIQ-Booking-Assistance/renderer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
const { ipcRenderer } = require('electron')

const accessibilityRoomYes = document.getElementById('accessibilityRoom_yes');
const accessibilityRoomNo = document.getElementById('accessibilityRoom_no');
const findAnyDateYes = document.getElementById('findAnyDate_yes');
const findAnyDateNo = document.getElementById('findAnyDate_no');
const roomType = document.getElementById('roomType');
const dateButton = document.getElementById('date-button');
const monthButton = document.getElementById('month-button');
const dateList = document.getElementById('date-list');
Expand Down Expand Up @@ -36,10 +33,6 @@ ipcRenderer.on('available', function (evt, message) {
resetButton.disabled = false;
});

accessibilityRoomYes.addEventListener('change', sendSettings)
accessibilityRoomNo.addEventListener('change', sendSettings)
roomType.addEventListener('change', sendSettings)

dateButton.addEventListener('click', () => {
if(dateInput.value && dates.indexOf(dateInput.value) === -1){
dates.push(dateInput.value);
Expand Down Expand Up @@ -94,8 +87,6 @@ function sendSettings(reset = false){
'settings',
{
dates: dates,
accessibilityRequirement: accessibilityRoomYes.checked,
roomType: roomType.value,
findAnyDate: findAnyDateYes.checked,
reset: reset,
refreshTime: refreshTime.value
Expand Down

0 comments on commit d803a18

Please sign in to comment.