jvolker / miq-nz-booking-tools

Tools to help booking a spot in New Zealand Managed Isolation and Quarantine. Automatically refreshes, checks and fills forms in the website to find and book the rare spots.
MIT License
83 stars 35 forks source link

Feature Requests: (i) Stop Page Refresh on Day Selection and (ii) Randomize the fixed refresh interval? #132

Open jksmurf opened 3 years ago

jksmurf commented 3 years ago

Apologies if this appears to be repeated but I made a couple of posts in 2 (long) threads yesterday that were closed overnight (without specifically addressing these), so I wanted to put these out there again.

(i) In one of the closed threads TigaNZ wrote:

No, the key assignment shouldn't matter. I had put it on something closer as well because hitting it manually was easier with a closer key, more or less the same as you. What I'm suggesting is missing those 1st recaptchas when you 1st login, even though they are often stupidly wrong... sets you up to get more on the appointment page...which will sabotage an opportunity.

I was just testing the F8 AutoHotKey script after running the 'npm start' (commandline) version of the script with the manual date inputs to the miq-assistance.js script and came across an issue that because the main script run from the cmd window keeps refreshing the MIQ page every 5s (or whatever interval you selected), if you haven't completed the Catchpa on the "Secure Allocation" page within 5 seconds, you miss out actually being able to click next as the Catchpa disappears (i.e. you will lose the spot). Is there some way of getting the script to stop doing the 5s refresh after you get a date hit that matches the dates you put in the miq-assistance.js script?

Apologies if it does actually work like that when it finds your date, I am just unable to test it on actual dates as they come up so seldom.

(ii) I was also wondering if it were possible to add a wee function to randomize the fixed refresh interval between an upper and lower limit so it was not always "exactly" 5s; e.g. if you set 4 and 6 seconds as these U/L bounds and it will (using some random generator), generate a number from 0 to 2 (to 2 sig figs e.g. 0.1, 1.5, 0.8) so that the refresh becomes slightly more random i.e. for those examples, 4.1, 5.5, 4.8 seconds) etc. Just a thought.

Thanks

k.

darianbird commented 3 years ago

I'm not a developer by any means so this is messy but adding in a few lines of code solves ii.

You can set max and min refresh times up the top of the script where secondsTillRefresh is defined.

let secondsTillRefreshMax = 15.7; let secondsTillRefreshMin = 14.1;

Later in the prepareAndCheckPage function, you can add the following line so that each time the page refreshes, secondsTillRefresh changes randomly between the min and max amounts. I tried using this code up the top of the script but it didn't work as it only randomly changes the number once.

secondsTillRefresh = Math.random() * (secondsTillRefreshMax - secondsTillRefreshMin) + secondsTillRefreshMin;

I've also added

const status = 'Checked MIQ: ' + ++checkedCount + ' times, last checked at: ' + new Date().toLocaleString()

to confirm that secondsTillRefresh is in fact changing each time by showing it in the console.

jksmurf commented 3 years ago

I'm not a developer by any means so this is messy but adding in a few lines of code solves ii.

You can set max and min refresh times up the top of the script where secondsTillRefresh is defined.

let secondsTillRefreshMax = 15.7; let secondsTillRefreshMin = 14.1;

Later in the prepareAndCheckPage function, you can add the following line so that each time the page refreshes, secondsTillRefresh changes randomly between the min and max amounts. I tried using this code up the top of the script but it didn't work as it only randomly changes the number once.

secondsTillRefresh = Math.random() * (secondsTillRefreshMax - secondsTillRefreshMin) + secondsTillRefreshMin;

I've also added

  • ' secondsTillRefresh = ' + secondsTillRefresh;

to the end of this line

const status = 'Checked MIQ: ' + ++checkedCount + ' times, last checked at: ' + new Date().toLocaleString()

to confirm that secondsTillRefresh is in fact changing each time by showing it in the console.

Wow, that's awesome, thank you. Presumably this is added to to the MIQ-assistance.js file?

Would you be able to attach the file with the changes added so I can use it as the base file? Presumably you meant these numbers i.e. from 4.1-5.7 (not 14.1-15.7?)

let secondsTillRefreshMax = 5.7; let secondsTillRefreshMin = 4.1;

Finally, I cannot see an increment for the change e.g. 0.1 (although I may have missed it?) Does Math.random() have a sig fig default?

Cheers

k.

darianbird commented 3 years ago

You can use any number you like for min and max. If the average is below about 4.5 it kicks you out after not too long. Even if it's well above 5, it'll log you out after 537 refreshes. I use 15 while I'm sleeping and much less while I'm awake. Today I'm testing if I can get those sleeping numbers down. There must be some max number of refreshes in a certain period of time but I have a feeling it changes perhaps according to the time - sometimes after 9am NZT I have to increase it but that might just be a coincidence.

As far as I can see, that line creates a random number out to 14 decimal places at least, i.e. it's not related to how many dp you use on min and max.

Yes, it's added to MIQ-assistance.js . I'm not using the .exe but running CMD in the folder, first time you make changes type npm i then npm start . If you have the exe working, I assume it'll continue working with these changes.

I'd prefer not to upload my full .js file as I've made several other changes while experimenting and it's quite a mess and I've even broken some parts of it somehow. I'm using today while MIQ isn't releasing rooms to try to clean it all up.

This is how I have it inside prepareAndCheckPage, i.e. edit the const status line and add the secondsTillRefresh below it

    const status = 'Checked MIQ: ' + ++checkedCount + ' times, last checked at: ' + new Date().toLocaleString() + ' errorRefreshes = ' + errorRefreshes + ' secondsTillRefresh = ' + secondsTillRefresh;
    secondsTillRefresh = Math.random() * (secondsTillRefreshMax - secondsTillRefreshMin) + secondsTillRefreshMin;

I only did this a couple of days ago and haven't noticed if it affects the reCAPTCHA success or not as I've had so few of my dates turn up so far.

jksmurf commented 3 years ago

Cheers bennyggg will give it a whirl on the w/e.

Have you perchance had any issues with the 1st item above, that the page refresh blows away your attempts to complete Catchpa to then hit next?

jksmurf commented 3 years ago
    const status = 'Checked MIQ: ' + ++checkedCount + ' times, last checked at: ' + new Date().toLocaleString() + ' errorRefreshes = ' + errorRefreshes + ' secondsTillRefresh = ' + secondsTillRefresh;
    secondsTillRefresh = Math.random() * (secondsTillRefreshMax - secondsTillRefreshMin) + secondsTillRefreshMin;

Works a treat bennyggg , although I don't have an errorRefreshes function, so I took that bit out because it was crashing with it in. Thanks again. I made two Batch files directed at two separate (independent) folders, one with the 5s and one with the 15s version.

darianbird commented 3 years ago
    const status = 'Checked MIQ: ' + ++checkedCount + ' times, last checked at: ' + new Date().toLocaleString() + ' errorRefreshes = ' + errorRefreshes + ' secondsTillRefresh = ' + secondsTillRefresh;
    secondsTillRefresh = Math.random() * (secondsTillRefreshMax - secondsTillRefreshMin) + secondsTillRefreshMin;

Works a treat bennyggg , although I don't have an errorRefreshes function, so I took that bit out because it was crashing with it in. Thanks again. I made two Batch files directed at two separate (independent) folders, one with the 5s and one with the 15s version.

Oh yes, I forgot to delete the errorRefreshes part. That was something I was messing around with earlier.

Regarding (i) I had a problem a couple of times but then other times it seemed to stop and gave me time to complete the captcha (but of course I was too slow to secure the spot). I'll test it with findanydate = true and see if I can consistently recreate the issue but with the pause at MIQ it's hard to do any real-world testing.