feat: add delay on captcha to try and evade faster (#119)

This commit is contained in:
Mark Dietzer
2020-09-20 11:27:10 -07:00
committed by GitHub
parent c0352961a9
commit 4f83b3b233
3 changed files with 16 additions and 6 deletions
+2 -1
View File
@@ -4,7 +4,8 @@ import adblockerPlugin from 'puppeteer-extra-plugin-adblocker';
import {Config} from './config';
import {Stores} from './store/model';
import {Logger} from './logger';
import {getSleepTime, tryLookupAndLoop} from './store';
import {tryLookupAndLoop} from './store';
import {getSleepTime} from './util';
puppeteer.use(stealthPlugin());
puppeteer.use(adblockerPlugin({blockTrackers: true}));
+3 -5
View File
@@ -5,6 +5,7 @@ import open from 'open';
import {Store} from './model';
import {sendNotification} from '../notification';
import {includesLabels} from './includes-labels';
import {delay, getSleepTime} from '../util';
/**
* Returns true if the brand should be checked for stock
@@ -56,7 +57,8 @@ async function lookup(browser: Browser, store: Store) {
if (includesLabels(textContent, link.oosLabels)) {
Logger.info(`✖ [${store.name}] still out of stock: ${graphicsCard}`);
} else if (link.captchaLabels && includesLabels(textContent, link.captchaLabels)) {
Logger.warn(`✖ [${store.name}] CAPTCHA from: ${graphicsCard}`);
Logger.warn(`✖ [${store.name}] CAPTCHA from: ${graphicsCard}. Waiting for a bit with this store...`);
await delay(getSleepTime());
} else if (response && response.status() === 429) {
Logger.warn(`✖ [${store.name}] Rate limit exceeded: ${graphicsCard}`);
} else {
@@ -82,10 +84,6 @@ async function lookup(browser: Browser, store: Store) {
/* eslint-enable no-await-in-loop */
}
export function getSleepTime() {
return Config.browser.minSleep + (Math.random() * (Config.browser.maxSleep - Config.browser.minSleep));
}
export async function tryLookupAndLoop(browser: Browser, store: Store) {
Logger.debug(`[${store.name}] Starting lookup...`);
try {
+11
View File
@@ -0,0 +1,11 @@
import {Config} from './config';
export function getSleepTime() {
return Config.browser.minSleep + (Math.random() * (Config.browser.maxSleep - Config.browser.minSleep));
}
export async function delay(ms: number) {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
}