mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 09:57:38 +00:00
feat: in stock wait time per link now
Signed-off-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
+8
-1
@@ -35,11 +35,18 @@ export const Print = {
|
||||
},
|
||||
inStock(link: Link, store: Store, color?: boolean): string {
|
||||
if (color) {
|
||||
return chalk.green.bold(`🚀🚨 ${buildProductString(link, store, true)} :: IN STOCK 🚨🚀`);
|
||||
return chalk.bgGreen.white.bold(`🚀🚨 ${buildProductString(link, store, false)} :: IN STOCK 🚨🚀`);
|
||||
}
|
||||
|
||||
return `🚀🚨 ${buildProductString(link, store)} :: IN STOCK 🚨🚀`;
|
||||
},
|
||||
inStockWaiting(link: Link, store: Store, color?: boolean): string {
|
||||
if (color) {
|
||||
return 'ℹ ' + buildProductString(link, store, true) + ' :: ' + chalk.yellow('IN STOCK, WAITING');
|
||||
}
|
||||
|
||||
return `ℹ ${buildProductString(link, store)} :: IN STOCK, WAITING`;
|
||||
},
|
||||
outOfStock(link: Link, store: Store, color?: boolean): string {
|
||||
if (color) {
|
||||
return '✖ ' + buildProductString(link, store, true) + ' :: ' + chalk.red('OUT OF STOCK');
|
||||
|
||||
+8
-7
@@ -25,6 +25,11 @@ async function lookup(browser: Browser, store: Store) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Config.page.inStockWaitTime && inStock[store.name]) {
|
||||
Logger.info(Print.inStockWaiting(link, store, true));
|
||||
continue;
|
||||
}
|
||||
|
||||
const page = await browser.newPage();
|
||||
page.setDefaultNavigationTimeout(Config.page.navigationTimeout);
|
||||
await page.setUserAgent(Config.page.userAgent);
|
||||
@@ -59,10 +64,10 @@ async function lookupCard(browser: Browser, store: Store, page: Page, link: Link
|
||||
sendNotification(link, store);
|
||||
|
||||
if (Config.page.inStockWaitTime) {
|
||||
inStock[store.name] = true;
|
||||
inStock[link.url] = true;
|
||||
|
||||
setTimeout(() => {
|
||||
inStock[store.name] = false;
|
||||
inStock[link.url] = false;
|
||||
}, 1000 * Config.page.inStockWaitTime);
|
||||
}
|
||||
|
||||
@@ -119,11 +124,7 @@ async function lookupPageHasCaptcha(store: Store, page: Page) {
|
||||
export async function tryLookupAndLoop(browser: Browser, store: Store) {
|
||||
Logger.debug(`[${store.name}] Starting lookup...`);
|
||||
try {
|
||||
if (Config.page.inStockWaitTime && inStock[store.name]) {
|
||||
Logger.info(`[${store.name}] Has stock, waiting before trying to lookup again...`);
|
||||
} else {
|
||||
await lookup(browser, store);
|
||||
}
|
||||
await lookup(browser, store);
|
||||
} catch (error) {
|
||||
Logger.error(error);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user