mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 07:37:39 +00:00
chore: refactor max price for series
Signed-off-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
@@ -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` |
|
| `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` |
|
| `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` |
|
| `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` |
|
| `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_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` |
|
| `NVIDIA_SESSION_TTL` | The time in milliseconds to keep the cart active while using `nvidia-api` | Default: `60000` |
|
||||||
|
|||||||
+14
-3
@@ -1,7 +1,9 @@
|
|||||||
import {banner} from './banner';
|
import {banner} from './banner';
|
||||||
|
|
||||||
console.log(banner);
|
console.log(banner);
|
||||||
|
|
||||||
import {config as config_} from 'dotenv';
|
import {config as config_} from 'dotenv';
|
||||||
|
import {logger} from './logger';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
|
|
||||||
config_({path: path.resolve(__dirname, '../.env')});
|
config_({path: path.resolve(__dirname, '../.env')});
|
||||||
@@ -141,11 +143,20 @@ const proxy = {
|
|||||||
port: envOrNumber(process.env.PROXY_PORT, 80)
|
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 = {
|
const store = {
|
||||||
country: envOrString(process.env.COUNTRY, 'usa'),
|
country: envOrString(process.env.COUNTRY, 'usa'),
|
||||||
maxPrice3070: envOrNumber(process.env.MAX_PRICE_3070),
|
maxPrice: {
|
||||||
maxPrice3080: envOrNumber(process.env.MAX_PRICE_3080),
|
series: {
|
||||||
maxPrice3090: envOrNumber(process.env.MAX_PRICE_3090),
|
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'),
|
microCenterLocation: envOrString(process.env.MICROCENTER_LOCATION, 'web'),
|
||||||
showOnlyBrands: envOrArray(process.env.SHOW_ONLY_BRANDS),
|
showOnlyBrands: envOrArray(process.env.SHOW_ONLY_BRANDS),
|
||||||
showOnlyModels: envOrArray(process.env.SHOW_ONLY_MODELS),
|
showOnlyModels: envOrArray(process.env.SHOW_ONLY_MODELS),
|
||||||
|
|||||||
@@ -40,11 +40,6 @@ async function main() {
|
|||||||
args.push(`--proxy-server=http://${config.proxy.address}:${config.proxy.port}`);
|
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({
|
const browser = await puppeteer.launch({
|
||||||
args,
|
args,
|
||||||
defaultViewport: {
|
defaultViewport: {
|
||||||
|
|||||||
+3
-3
@@ -78,12 +78,12 @@ export const Print = {
|
|||||||
|
|
||||||
return `ℹ ${buildProductString(link, store)} :: IN STOCK, WAITING`;
|
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) {
|
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 {
|
message(message: string, topic: string, store: Store, color?: boolean): string {
|
||||||
if (color) {
|
if (color) {
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ export async function pageIncludesLabels(page: Page, query: LabelQuery, options:
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function extractPageContents(page: Page, selector: Selector): Promise<string | null> {
|
export async function extractPageContents(page: Page, selector: Selector): Promise<string | null> {
|
||||||
const content = await page.evaluate((options: Selector) => {
|
return page.evaluate((options: Selector) => {
|
||||||
// eslint-disable-next-line no-undef
|
// eslint-disable-next-line no-undef
|
||||||
const element: globalThis.HTMLElement | null = document.querySelector(options.selector);
|
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';
|
return 'Error: selector.type is unknown';
|
||||||
}
|
}
|
||||||
}, selector);
|
}, selector);
|
||||||
|
|
||||||
return content;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -91,7 +89,7 @@ export function includesLabels(domText: string, searchLabels: string[]): boolean
|
|||||||
return searchLabels.some(label => domTextLowerCase.includes(label));
|
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) {
|
if (!max) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-10
@@ -1,7 +1,7 @@
|
|||||||
import {Browser, Page, Response} from 'puppeteer';
|
import {Browser, Page, Response} from 'puppeteer';
|
||||||
import {Link, Store} from './model';
|
import {Link, Store} from './model';
|
||||||
import {Print, logger} from '../logger';
|
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 {closePage, delay, getSleepTime, isStatusCodeInRange} from '../util';
|
||||||
import {config} from '../config';
|
import {config} from '../config';
|
||||||
import {disableBlockerInPage} from '../adblocker';
|
import {disableBlockerInPage} from '../adblocker';
|
||||||
@@ -149,27 +149,27 @@ async function lookupCardInStock(store: Store, page: Page, link: Link) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (store.labels.maxPrice) {
|
if (store.labels.maxPrice) {
|
||||||
let priceLimit;
|
let price;
|
||||||
let maxPrice = 0;
|
let maxPrice = 0;
|
||||||
switch (link.series) {
|
switch (link.series) {
|
||||||
case '3070':
|
case '3070':
|
||||||
priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3070, baseOptions);
|
price = await cardPrice(page, store.labels.maxPrice, config.store.maxPrice.series['3070'], baseOptions);
|
||||||
maxPrice = config.store.maxPrice3070;
|
maxPrice = config.store.maxPrice.series['3070'];
|
||||||
break;
|
break;
|
||||||
case '3080':
|
case '3080':
|
||||||
priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3080, baseOptions);
|
price = await cardPrice(page, store.labels.maxPrice, config.store.maxPrice.series['3080'], baseOptions);
|
||||||
maxPrice = config.store.maxPrice3080;
|
maxPrice = config.store.maxPrice.series['3080'];
|
||||||
break;
|
break;
|
||||||
case '3090':
|
case '3090':
|
||||||
priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3090, baseOptions);
|
price = await cardPrice(page, store.labels.maxPrice, config.store.maxPrice.series['3080'], baseOptions);
|
||||||
maxPrice = config.store.maxPrice3090;
|
maxPrice = config.store.maxPrice.series['3090'];
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priceLimit) {
|
if (price) {
|
||||||
logger.info(Print.maxPrice(link, store, priceLimit, maxPrice, true));
|
logger.info(Print.maxPrice(link, store, price, maxPrice, true));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user