mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 02:57:34 +00:00
feat: temporarily pause requests if store has stock (#147)
Co-authored-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
@@ -3,6 +3,7 @@ DISCORD_WEB_HOOK="https://discordapp.com/api/webhooks/23123123123/5dfsdfh3h2j5hd
|
|||||||
EMAIL_USERNAME="youremail@gmail.com"
|
EMAIL_USERNAME="youremail@gmail.com"
|
||||||
EMAIL_PASSWORD="secretpassword"
|
EMAIL_PASSWORD="secretpassword"
|
||||||
HEADLESS="true"
|
HEADLESS="true"
|
||||||
|
IN_STOCK_WAIT_TIME="30"
|
||||||
LOG_LEVEL="info"
|
LOG_LEVEL="info"
|
||||||
OPEN_BROWSER="true"
|
OPEN_BROWSER="true"
|
||||||
PAGE_TIMEOUT="30000"
|
PAGE_TIMEOUT="30000"
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ Here is a list of variables that you can use to customize your newly copied `.en
|
|||||||
| `EMAIL_USERNAME` | Gmail address | E.g.: `jensen.robbed.us@gmail.com` |
|
| `EMAIL_USERNAME` | Gmail address | E.g.: `jensen.robbed.us@gmail.com` |
|
||||||
| `EMAIL_PASSWORD` | Gmail password | See below if you have MFA |
|
| `EMAIL_PASSWORD` | Gmail password | See below if you have MFA |
|
||||||
| `HEADLESS` | Puppeteer to run headless or not | Debugging related, default: `true` |
|
| `HEADLESS` | Puppeteer to run headless or not | Debugging related, default: `true` |
|
||||||
|
| `IN_STOCK_WAIT_TIME` | Time to wait between requests to the same store if it has cards in stock | In seconds, default: `0` |
|
||||||
| `LOG_LEVEL` | [Logging levels](https://github.com/winstonjs/winston#logging-levels) | Debugging related, default: `info` |
|
| `LOG_LEVEL` | [Logging levels](https://github.com/winstonjs/winston#logging-levels) | Debugging related, default: `info` |
|
||||||
| `OPEN_BROWSER` | Toggle for whether or not the browser should open when item is found | Default: `true` |
|
| `OPEN_BROWSER` | Toggle for whether or not the browser should open when item is found | Default: `true` |
|
||||||
| `PAGE_TIMEOUT` | Navigation Timeout in milliseconds | `0` for infinite, default: `30000` |
|
| `PAGE_TIMEOUT` | Navigation Timeout in milliseconds | `0` for infinite, default: `30000` |
|
||||||
|
|||||||
+2
-1
@@ -56,7 +56,8 @@ const page = {
|
|||||||
width: 1920,
|
width: 1920,
|
||||||
height: 1080,
|
height: 1080,
|
||||||
navigationTimeout: Number(process.env.PAGE_TIMEOUT ?? 30000),
|
navigationTimeout: Number(process.env.PAGE_TIMEOUT ?? 30000),
|
||||||
userAgent: process.env.USER_AGENT ?? 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36'
|
userAgent: process.env.USER_AGENT ?? 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36',
|
||||||
|
inStockWaitTime: Number(process.env.IN_STOCK_WAIT_TIME ?? 0)
|
||||||
};
|
};
|
||||||
|
|
||||||
const store = {
|
const store = {
|
||||||
|
|||||||
+13
-1
@@ -7,6 +7,8 @@ import {sendNotification} from '../notification';
|
|||||||
import {includesLabels} from './includes-labels';
|
import {includesLabels} from './includes-labels';
|
||||||
import {closePage, delay, getSleepTime} from '../util';
|
import {closePage, delay, getSleepTime} from '../util';
|
||||||
|
|
||||||
|
const inStock: Record<string, boolean> = {};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if the brand should be checked for stock
|
* Returns true if the brand should be checked for stock
|
||||||
*
|
*
|
||||||
@@ -81,6 +83,12 @@ async function lookup(browser: Browser, store: Store) {
|
|||||||
} else {
|
} else {
|
||||||
Logger.info(`🚀🚀🚀 [${store.name}] ${graphicsCard} IN STOCK 🚀🚀🚀`);
|
Logger.info(`🚀🚀🚀 [${store.name}] ${graphicsCard} IN STOCK 🚀🚀🚀`);
|
||||||
Logger.info(link.url);
|
Logger.info(link.url);
|
||||||
|
if (Config.page.inStockWaitTime) {
|
||||||
|
inStock[store.name] = true;
|
||||||
|
setTimeout(() => {
|
||||||
|
inStock[store.name] = false;
|
||||||
|
}, 1000 * Config.page.inStockWaitTime);
|
||||||
|
}
|
||||||
|
|
||||||
if (Config.page.capture) {
|
if (Config.page.capture) {
|
||||||
Logger.debug('ℹ saving screenshot');
|
Logger.debug('ℹ saving screenshot');
|
||||||
@@ -109,7 +117,11 @@ async function lookup(browser: Browser, store: Store) {
|
|||||||
export async function tryLookupAndLoop(browser: Browser, store: Store) {
|
export async function tryLookupAndLoop(browser: Browser, store: Store) {
|
||||||
Logger.debug(`[${store.name}] Starting lookup...`);
|
Logger.debug(`[${store.name}] Starting lookup...`);
|
||||||
try {
|
try {
|
||||||
await lookup(browser, store);
|
if (Config.page.inStockWaitTime && inStock[store.name]) {
|
||||||
|
Logger.info(`[${store.name}] Has stock, waiting before trying to lookup again...`);
|
||||||
|
} else {
|
||||||
|
await lookup(browser, store);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
Logger.error(error);
|
Logger.error(error);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user