diff --git a/README.md b/README.md index 5f83886..1998269 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,9 @@ Here is a list of variables that you can use to customize your newly copied `.en | `IN_STOCK_WAIT_TIME` | Time to wait between requests to the same link if it has that card in stock | In seconds, default: `0` | | `LOG_LEVEL` | [Logging levels](https://github.com/winstonjs/winston#logging-levels) | Debugging related, default: `info` | | `LOW_BANDWIDTH` | Blocks images/fonts to reduce traffic | Disables ad blocker, default: `false` | -| `MAX_PRICE` | Maximum price allowed for a match, applies to all cards (does not apply to these sites: Nvidia, Asus, EVGA) | Default: leave empty for no limit, otherwise enter a price (enter whole dollar amounts only, avoid use of: dollar symbols, commas, and periods.) e.g.: `1234` - Cards above `1234` will be skipped. | +| `MAX_PRICE_SERIES_3070` | Maximum price allowed for a match, applies 3070 series cards (does not apply to these sites: Nvidia, Asus, EVGA) | Default: leave empty for no limit, otherwise enter a price (enter whole dollar amounts only, avoid use of: dollar symbols, commas, and periods.) e.g.: `1234` - Cards above `1234` will be skipped. | +| `MAX_PRICE_SERIES_3080` | Maximum price allowed for a match, applies 3080 series cards (does not apply to these sites: Nvidia, Asus, EVGA) | Default: leave empty for no limit, otherwise enter a price (enter whole dollar amounts only, avoid use of: dollar symbols, commas, and periods.) e.g.: `1234` - Cards above `1234` will be skipped. | +| `MAX_PRICE_SERIES_3090` | Maximum price allowed for a match, applies 3090 series cards (does not apply to these sites: Nvidia, Asus, EVGA) | Default: leave empty for no limit, otherwise enter a price (enter whole dollar amounts only, avoid use of: dollar symbols, commas, and periods.) e.g.: `1234` - Cards above `1234` will be skipped. | | `MICROCENTER_LOCATION` | Specific MicroCenter location to search | Default : `web` | | `NVIDIA_ADD_TO_CART_ATTEMPTS` | The maximum number of times the `nvidia-api` add to cart feature will be attempted before failing | Default: `10` | | `NVIDIA_SESSION_TTL` | The time in milliseconds to keep the cart active while using `nvidia-api` | Default: `60000` | diff --git a/src/config.ts b/src/config.ts index e73967d..8dd6b56 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,7 +1,9 @@ import {banner} from './banner'; + console.log(banner); import {config as config_} from 'dotenv'; +import {logger} from './logger'; import path from 'path'; config_({path: path.resolve(__dirname, '../.env')}); @@ -141,11 +143,20 @@ const proxy = { port: envOrNumber(process.env.PROXY_PORT, 80) }; +// Check for deprecated configuration values +if (process.env.MAX_PRICE) { + logger.warn('ℹ MAX_PRICE is deprecated, please use MAX_PRICE_SERIES_{{series}}'); +} + const store = { country: envOrString(process.env.COUNTRY, 'usa'), - maxPrice3070: envOrNumber(process.env.MAX_PRICE_3070), - maxPrice3080: envOrNumber(process.env.MAX_PRICE_3080), - maxPrice3090: envOrNumber(process.env.MAX_PRICE_3090), + maxPrice: { + series: { + 3070: envOrNumber(process.env.MAX_PRICE_3070), + 3080: envOrNumber(process.env.MAX_PRICE_3080), + 3090: envOrNumber(process.env.MAX_PRICE_3090) + } + }, microCenterLocation: envOrString(process.env.MICROCENTER_LOCATION, 'web'), showOnlyBrands: envOrArray(process.env.SHOW_ONLY_BRANDS), showOnlyModels: envOrArray(process.env.SHOW_ONLY_MODELS), diff --git a/src/index.ts b/src/index.ts index 051805b..554b71c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -40,11 +40,6 @@ async function main() { args.push(`--proxy-server=http://${config.proxy.address}:${config.proxy.port}`); } - // Check for deprecated configuration values - if (process.env.MAX_PRICE) { - logger.warn('ℹ MAX_PRICE is deprecated, please use MAX_PRICE_$[series]'); - } - const browser = await puppeteer.launch({ args, defaultViewport: { diff --git a/src/logger.ts b/src/logger.ts index 2b682d5..69914b0 100644 --- a/src/logger.ts +++ b/src/logger.ts @@ -78,12 +78,12 @@ export const Print = { return `ℹ ${buildProductString(link, store)} :: IN STOCK, WAITING`; }, - maxPrice(link: Link, store: Store, price: number, setPrice: number, color?: boolean): string { + maxPrice(link: Link, store: Store, price: number, maxPrice: number, color?: boolean): string { if (color) { - return '✖ ' + buildProductString(link, store, true) + ' :: ' + chalk.yellow(`PRICE ${price} EXCEEDS LIMIT ${setPrice}`); + return '✖ ' + buildProductString(link, store, true) + ' :: ' + chalk.yellow(`PRICE ${price} EXCEEDS LIMIT ${maxPrice}`); } - return `✖ ${buildProductString(link, store)} :: PRICE ${price} EXCEEDS LIMIT ${setPrice}`; + return `✖ ${buildProductString(link, store)} :: PRICE ${price} EXCEEDS LIMIT ${maxPrice}`; }, message(message: string, topic: string, store: Store, color?: boolean): string { if (color) { diff --git a/src/store/includes-labels.ts b/src/store/includes-labels.ts index e48d4dd..841140a 100644 --- a/src/store/includes-labels.ts +++ b/src/store/includes-labels.ts @@ -53,7 +53,7 @@ export async function pageIncludesLabels(page: Page, query: LabelQuery, options: } export async function extractPageContents(page: Page, selector: Selector): Promise { - const content = await page.evaluate((options: Selector) => { + return page.evaluate((options: Selector) => { // eslint-disable-next-line no-undef const element: globalThis.HTMLElement | null = document.querySelector(options.selector); @@ -76,8 +76,6 @@ export async function extractPageContents(page: Page, selector: Selector): Promi return 'Error: selector.type is unknown'; } }, selector); - - return content; } /** @@ -91,7 +89,7 @@ export function includesLabels(domText: string, searchLabels: string[]): boolean return searchLabels.some(label => domTextLowerCase.includes(label)); } -export async function cardPriceLimit(page: Page, query: Pricing, max: number, options: Selector) { +export async function cardPrice(page: Page, query: Pricing, max: number, options: Selector) { if (!max) { return null; } diff --git a/src/store/lookup.ts b/src/store/lookup.ts index 820ef65..0a216ea 100644 --- a/src/store/lookup.ts +++ b/src/store/lookup.ts @@ -1,7 +1,7 @@ import {Browser, Page, Response} from 'puppeteer'; import {Link, Store} from './model'; import {Print, logger} from '../logger'; -import {Selector, cardPriceLimit, pageIncludesLabels} from './includes-labels'; +import {Selector, cardPrice, pageIncludesLabels} from './includes-labels'; import {closePage, delay, getSleepTime, isStatusCodeInRange} from '../util'; import {config} from '../config'; import {disableBlockerInPage} from '../adblocker'; @@ -149,27 +149,27 @@ async function lookupCardInStock(store: Store, page: Page, link: Link) { } if (store.labels.maxPrice) { - let priceLimit; + let price; let maxPrice = 0; switch (link.series) { case '3070': - priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3070, baseOptions); - maxPrice = config.store.maxPrice3070; + price = await cardPrice(page, store.labels.maxPrice, config.store.maxPrice.series['3070'], baseOptions); + maxPrice = config.store.maxPrice.series['3070']; break; case '3080': - priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3080, baseOptions); - maxPrice = config.store.maxPrice3080; + price = await cardPrice(page, store.labels.maxPrice, config.store.maxPrice.series['3080'], baseOptions); + maxPrice = config.store.maxPrice.series['3080']; break; case '3090': - priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3090, baseOptions); - maxPrice = config.store.maxPrice3090; + price = await cardPrice(page, store.labels.maxPrice, config.store.maxPrice.series['3080'], baseOptions); + maxPrice = config.store.maxPrice.series['3090']; break; default: break; } - if (priceLimit) { - logger.info(Print.maxPrice(link, store, priceLimit, maxPrice, true)); + if (price) { + logger.info(Print.maxPrice(link, store, price, maxPrice, true)); return false; } }