mirror of
https://github.com/opelly27/streetmerchant.git
synced 2026-05-20 04:07:36 +00:00
feat: max price per series (#451)
This commit is contained in:
+3
-1
@@ -13,7 +13,9 @@ HEADLESS=""
|
||||
IN_STOCK_WAIT_TIME=""
|
||||
LOG_LEVEL=""
|
||||
LOW_BANDWIDTH=""
|
||||
MAX_PRICE=""
|
||||
MAX_PRICE_3070=""
|
||||
MAX_PRICE_3080=""
|
||||
MAX_PRICE_3090=""
|
||||
MICROCENTER_LOCATION=""
|
||||
NVIDIA_ADD_TO_CART_ATTEMPTS=""
|
||||
NVIDIA_SESSION_TTL=""
|
||||
|
||||
+3
-1
@@ -143,7 +143,9 @@ const proxy = {
|
||||
|
||||
const store = {
|
||||
country: envOrString(process.env.COUNTRY, 'usa'),
|
||||
maxPrice: envOrNumber(process.env.MAX_PRICE),
|
||||
maxPrice3070: envOrNumber(process.env.MAX_PRICE_3070),
|
||||
maxPrice3080: envOrNumber(process.env.MAX_PRICE_3080),
|
||||
maxPrice3090: 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),
|
||||
|
||||
@@ -40,6 +40,11 @@ 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: {
|
||||
|
||||
+3
-3
@@ -78,12 +78,12 @@ export const Print = {
|
||||
|
||||
return `ℹ ${buildProductString(link, store)} :: IN STOCK, WAITING`;
|
||||
},
|
||||
maxPrice(link: Link, store: Store, price: number, color?: boolean): string {
|
||||
maxPrice(link: Link, store: Store, price: number, setPrice: number, color?: boolean): string {
|
||||
if (color) {
|
||||
return '✖ ' + buildProductString(link, store, true) + ' :: ' + chalk.yellow(`PRICE ${price} EXCEEDS LIMIT ${config.store.maxPrice}`);
|
||||
return '✖ ' + buildProductString(link, store, true) + ' :: ' + chalk.yellow(`PRICE ${price} EXCEEDS LIMIT ${setPrice}`);
|
||||
}
|
||||
|
||||
return `✖ ${buildProductString(link, store)} :: PRICE ${price} EXCEEDS LIMIT ${config.store.maxPrice}`;
|
||||
return `✖ ${buildProductString(link, store)} :: PRICE ${price} EXCEEDS LIMIT ${setPrice}`;
|
||||
},
|
||||
message(message: string, topic: string, store: Store, color?: boolean): string {
|
||||
if (color) {
|
||||
|
||||
+20
-2
@@ -149,9 +149,27 @@ async function lookupCardInStock(store: Store, page: Page, link: Link) {
|
||||
}
|
||||
|
||||
if (store.labels.maxPrice) {
|
||||
const priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice, baseOptions);
|
||||
let priceLimit;
|
||||
let maxPrice = 0;
|
||||
switch (link.series) {
|
||||
case '3070':
|
||||
priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3070, baseOptions);
|
||||
maxPrice = config.store.maxPrice3070;
|
||||
break;
|
||||
case '3080':
|
||||
priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3080, baseOptions);
|
||||
maxPrice = config.store.maxPrice3080;
|
||||
break;
|
||||
case '3090':
|
||||
priceLimit = await cardPriceLimit(page, store.labels.maxPrice, config.store.maxPrice3090, baseOptions);
|
||||
maxPrice = config.store.maxPrice3090;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (priceLimit) {
|
||||
logger.info(Print.maxPrice(link, store, priceLimit, true));
|
||||
logger.info(Print.maxPrice(link, store, priceLimit, maxPrice, true));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user