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