Skip to content

Commit

Permalink
refactor(store): replace euroFormat with regex (#2131)
Browse files Browse the repository at this point in the history
  • Loading branch information
Meyer Paul committed Mar 14, 2021
1 parent afe7a70 commit 795c723
Show file tree
Hide file tree
Showing 98 changed files with 1 addition and 99 deletions.
3 changes: 1 addition & 2 deletions src/store/includes-labels.ts
Expand Up @@ -125,9 +125,8 @@ export async function getPrice(
const priceString = await extractPageContents(page, selector);

if (priceString) {
const priceSeparator = query.euroFormat ? /\./g : /,/g;
const price = Number.parseFloat(
priceString.replace(priceSeparator, '').match(/\d+/g)!.join('.')
priceString.replace(/\\.|\\,/g, '').match(/\d+/g)!.join('.') // eslint-disable-line
);

logger.debug('received price', price);
Expand Down
1 change: 0 additions & 1 deletion src/store/model/acompc.ts
Expand Up @@ -9,7 +9,6 @@ export const AComPC: Store = {
},
maxPrice: {
container: '.price',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/adorama.ts
Expand Up @@ -13,7 +13,6 @@ export const Adorama: Store = {
},
maxPrice: {
container: '.your-price',
euroFormat: false,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/akinformatica.ts
Expand Up @@ -15,7 +15,6 @@ export const Akinformatica: Store = {
],
maxPrice: {
container: '#PrezzoListinoIvatoLabel',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/allneeds.ts
Expand Up @@ -10,7 +10,6 @@ export const Allneeds: Store = {
},
maxPrice: {
container: 'span.price',
euroFormat: false,
},
outOfStock: {
container: '.amstockstatus',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/alternate-nl.ts
Expand Up @@ -9,7 +9,6 @@ export const AlternateNL: Store = {
},
maxPrice: {
container: 'div.price > span',
euroFormat: true,
},
outOfStock: {
container: '.stockStatus',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/alternate.ts
Expand Up @@ -14,7 +14,6 @@ export const Alternate: Store = {
},
maxPrice: {
container: 'div.price > span',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amazon-de-warehouse.ts
Expand Up @@ -17,7 +17,6 @@ export const AmazonDeWarehouse: Store = {
},
maxPrice: {
container: '.olpOfferPrice',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amazon-de.ts
Expand Up @@ -17,7 +17,6 @@ export const AmazonDe: Store = {
},
maxPrice: {
container: '#priceblock_ourprice',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amazon-fr.ts
Expand Up @@ -14,7 +14,6 @@ export const AmazonFr: Store = {
},
maxPrice: {
container: '#priceblock_ourprice',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amazon-it.ts
Expand Up @@ -14,7 +14,6 @@ export const AmazonIt: Store = {
},
maxPrice: {
container: '#priceblock_ourprice',
euroFormat: true,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amazon-nl.ts
Expand Up @@ -19,7 +19,6 @@ export const AmazonNl: Store = {
],
maxPrice: {
container: '#priceblock_ourprice',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amd-ca.ts
Expand Up @@ -9,7 +9,6 @@ export const AmdCa: Store = {
},
maxPrice: {
container: '.product-page-description h4',
euroFormat: false,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amd-de.ts
Expand Up @@ -9,7 +9,6 @@ export const AmdDe: Store = {
},
maxPrice: {
container: '.product-page-description h4',
euroFormat: true,
},
outOfStock: {
container: '.btn-radeon',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amd-it.ts
Expand Up @@ -9,7 +9,6 @@ export const AmdIt: Store = {
},
maxPrice: {
container: '.product-page-description h4',
euroFormat: true,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amd-uk.ts
Expand Up @@ -15,7 +15,6 @@ export const AmdUk: Store = {
],
maxPrice: {
container: '.product-page-description h4',
euroFormat: false,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/amd.ts
Expand Up @@ -9,7 +9,6 @@ export const Amd: Store = {
},
maxPrice: {
container: '.product-page-description h4',
euroFormat: false,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/antonline.ts
Expand Up @@ -9,7 +9,6 @@ export const AntOnline: Store = {
},
maxPrice: {
container: '.cPrice',
euroFormat: false,
},
outOfStock: {
container: '.priceView-price .priceView-hero-price span',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/aria.ts
Expand Up @@ -10,7 +10,6 @@ export const Aria: Store = {
},
maxPrice: {
container: '.priceBig',
euroFormat: false, // Note: Aria uses non-euroFromat as price seperator
},
outOfStock: {
container: '.fBox',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/arlt.ts
Expand Up @@ -9,7 +9,6 @@ export const Arlt: Store = {
},
maxPrice: {
container: '.articleprice .price',
euroFormat: true,
},
outOfStock: {
container: '.articleDesc .shippingtext',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/awd.ts
Expand Up @@ -10,7 +10,6 @@ export const Awd: Store = {
},
maxPrice: {
container: '.ty-price',
euroFormat: false, // Note: Awd uses non-euroFromat as price seperator
},
outOfStock: {
container: '.vs-stock.ty-float-left',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/azerty.ts
Expand Up @@ -9,7 +9,6 @@ export const Azerty: Store = {
},
maxPrice: {
container: '.mod_article .price',
euroFormat: true,
},
outOfStock: {
container: '.orderdelay',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/bandh.ts
Expand Up @@ -10,7 +10,6 @@ export const BAndH: Store = {
},
maxPrice: {
container: 'div[data-selenium="pricingPrice"]',
euroFormat: false,
},
outOfStock: {
container: 'button[data-selenium="notifyAvailabilityButton"]',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/bestbuy-ca.ts
Expand Up @@ -5,7 +5,6 @@ export const BestBuyCa: Store = {
labels: {
maxPrice: {
container: 'div[class*="pricingContainer"]',
euroFormat: false,
},
outOfStock: {
container: '.addToCartButton:disabled',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/box.ts
Expand Up @@ -11,7 +11,6 @@ export const Box: Store = {
},
maxPrice: {
container: '.p-price',
euroFormat: false, // Note: Box uses non-euroFromat as price seperator
},
outOfStock: {
container: '#divBuyButton',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/bpctech.ts
Expand Up @@ -10,7 +10,6 @@ export const Bpctech: Store = {
},
maxPrice: {
container: 'div.price-box.price-final_price > span > span',
euroFormat: false,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/bpmpower.ts
Expand Up @@ -9,7 +9,6 @@ export const BpmPower: Store = {
},
maxPrice: {
container: 'p.prezzoScheda:nth-child(1)',
euroFormat: true,
},
outOfStock: {
container: '.dispoSiProd >span',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/canadacomputers.ts
Expand Up @@ -9,7 +9,6 @@ export const CanadaComputers: Store = {
},
maxPrice: {
container: '.h2-big > strong:nth-child(1)',
euroFormat: false,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/caseking.ts
Expand Up @@ -10,7 +10,6 @@ export const Caseking: Store = {
},
maxPrice: {
container: '#buybox .article_details_price',
euroFormat: true,
},
outOfStock: {
container: '.delivery_container',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/ccl.ts
Expand Up @@ -11,7 +11,6 @@ export const Ccl: Store = {
},
maxPrice: {
container: '#pnlPriceText > p',
euroFormat: false, // Note: CCL uses non-euroFromat as price seperator
},
outOfStock: {
container: '#pnlSoldOut',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/centrecom.ts
Expand Up @@ -10,7 +10,6 @@ export const Centrecom: Store = {
},
maxPrice: {
container: 'div.prod_price_current.product-price > span',
euroFormat: false,
},
outOfStock: {
container: '.prod_stores_stock > li:nth-child(1) > span:nth-child(2)',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/computeralliance.ts
Expand Up @@ -11,7 +11,6 @@ export const ComputerAlliance: Store = {
},
maxPrice: {
container: 'span.price',
euroFormat: false,
},
outOfStock: {
container:
Expand Down
1 change: 0 additions & 1 deletion src/store/model/computeruniverse.ts
Expand Up @@ -13,7 +13,6 @@ export const Computeruniverse: Store = {
},
maxPrice: {
container: '.product-price',
euroFormat: true,
},
outOfStock: {
container: '.availability',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/coolblue.ts
Expand Up @@ -9,7 +9,6 @@ export const Coolblue: Store = {
},
maxPrice: {
container: '.js-order-block .sales-price__current',
euroFormat: true,
},
outOfStock: {
container: '.product-order',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/coolmod.ts
Expand Up @@ -9,7 +9,6 @@ export const Coolmod: Store = {
},
maxPrice: {
container: '.text-price-total',
euroFormat: true,
},
outOfStock: {
container: '.product-availability',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/corsair.ts
Expand Up @@ -9,7 +9,6 @@ export const Corsair: Store = {
},
maxPrice: {
container: '.product-price',
euroFormat: false,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/currys.ts
Expand Up @@ -10,7 +10,6 @@ export const Currys: Store = {
},
maxPrice: {
container: '#product-actions span[class*="ProductPriceBlock__Price"]',
euroFormat: false, // Note: Currys uses non-euroFromat as price seperator
},
outOfStock: {
container: '#product-actions .unavailable',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/cyberport.ts
Expand Up @@ -9,7 +9,6 @@ export const Cyberport: Store = {
},
maxPrice: {
container: '#productDetailOverview .price',
euroFormat: true,
},
outOfStock: {
container: '.tooltipAvailabilityParent',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/dcomp.ts
Expand Up @@ -10,7 +10,6 @@ export const Dcomp: Store = {
},
maxPrice: {
container: '#prodprice',
euroFormat: false,
},
outOfStock: {
container: '#cart-info > button.btn.notifyMe',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/drako.ts
Expand Up @@ -11,7 +11,6 @@ export const Drako: Store = {
],
maxPrice: {
container: '.price',
euroFormat: true,
},
},
links: [
Expand Down
1 change: 0 additions & 1 deletion src/store/model/ebuyer.ts
Expand Up @@ -10,7 +10,6 @@ export const Ebuyer: Store = {
},
maxPrice: {
container: '.purchase-info__price .price',
euroFormat: false, // Note: ebuyer uses non-euroFromat as price seperator
},
outOfStock: {
container: '.purchase-info',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/elcorteingles.ts
Expand Up @@ -19,7 +19,6 @@ export const Elcorteingles: Store = {
],
maxPrice: {
container: '.product_detail-buy-price-container .price._big',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/eprice.ts
Expand Up @@ -9,7 +9,6 @@ export const Eprice: Store = {
},
maxPrice: {
container: '#PrezzoClasic span[class*="big"]',
euroFormat: true,
},
outOfStock: {
container: '.dispo',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/equippr.ts
Expand Up @@ -9,7 +9,6 @@ export const Equippr: Store = {
},
maxPrice: {
container: '.product--price',
euroFormat: true,
},
outOfStock: {
container: '.product--buybox',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/euronics-de.ts
Expand Up @@ -9,7 +9,6 @@ export const EuronicsDE: Store = {
},
maxPrice: {
container: '.price--content',
euroFormat: true,
},
outOfStock: {
container:
Expand Down
1 change: 0 additions & 1 deletion src/store/model/evatech.ts
Expand Up @@ -10,7 +10,6 @@ export const Evatech: Store = {
},
maxPrice: {
container: '.product_detail_price',
euroFormat: false,
},
outOfStock: {
container: '.product_detail_add_to_cart > div:nth-child(2)',
Expand Down
1 change: 0 additions & 1 deletion src/store/model/expert.ts
Expand Up @@ -12,7 +12,6 @@ export const Expert: Store = {
],
maxPrice: {
container: '.widget-Container-subContent .widget-ArticlePrice-price',
euroFormat: false,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/futurex.ts
Expand Up @@ -9,7 +9,6 @@ export const Futurex: Store = {
},
maxPrice: {
container: '.price',
euroFormat: true,
},
outOfStock: [
{
Expand Down
1 change: 0 additions & 1 deletion src/store/model/galaxus.ts
Expand Up @@ -9,7 +9,6 @@ export const Galaxus: Store = {
},
maxPrice: {
container: '.productDetail .Z1c8',
euroFormat: true,
},
outOfStock: [
{
Expand Down

3 comments on commit 795c723

@nevkontakte
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello! I just wanted to give a heads-up that this commit may have broke something.

I was using streetmerchant docker image at nightly and recently it stopped honoring max price limit (I am in EU, and my prices are in euro). Rolling back to the stable latest label fixes the problem. Looking at the recent commit history, this is the only change that seems suspicious to me. caseking, amazon-de, amazon-es, amazon-nl are a few shops I have observed this problem with.

Cheers!

@carrierfry
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can also approve that this commit makes the program ignore price limits (at least with stores that use euro).

@vulpicastor
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can confirm that this is also broken for US stores with price > $1000, because it wrongly parses the thousands separator as a decimal comma.

Please sign in to comment.