mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 06:27:38 +00:00
feat: add delay on captcha to try and evade faster (#119)
This commit is contained in:
+2
-1
@@ -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
@@ -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
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user