chore: refactor max price for series

Signed-off-by: Jef LeCompte <jeffreylec@gmail.com>
This commit is contained in:
Jef LeCompte
2020-10-06 22:03:19 -04:00
parent 8adc07a03e
commit 86bef5a617
6 changed files with 32 additions and 26 deletions
+2 -4
View File
@@ -53,7 +53,7 @@ export async function pageIncludesLabels(page: Page, query: LabelQuery, options:
}
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
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;
}
+10 -10
View File
@@ -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;
}
}