mirror of
https://github.com/catdevnull/preciazo.git
synced 2025-02-20 01:06:25 +00:00
coto instock
This commit is contained in:
parent
6256817ee1
commit
e6f084b1da
1 changed files with 6 additions and 2 deletions
|
@ -19,7 +19,7 @@ function getEanFromText({ document }: Window) {
|
||||||
}
|
}
|
||||||
function getPriceFromText({ document }: Window) {
|
function getPriceFromText({ document }: Window) {
|
||||||
const el = document.querySelector(".atg_store_newPrice");
|
const el = document.querySelector(".atg_store_newPrice");
|
||||||
if (!el?.textContent) throw new Error("no encuentro el precio");
|
if (!el?.textContent) return null;
|
||||||
const nStr = el.textContent
|
const nStr = el.textContent
|
||||||
.trim()
|
.trim()
|
||||||
.replace("$", "")
|
.replace("$", "")
|
||||||
|
@ -27,12 +27,16 @@ function getPriceFromText({ document }: Window) {
|
||||||
.replace(",", ".");
|
.replace(",", ".");
|
||||||
return parseFloat(nStr) * 100;
|
return parseFloat(nStr) * 100;
|
||||||
}
|
}
|
||||||
|
function getInStock({ document }: Window) {
|
||||||
|
return !document.querySelector("product_not_available");
|
||||||
|
}
|
||||||
|
|
||||||
export function getCotoProduct(html: string | Buffer): Precioish {
|
export function getCotoProduct(html: string | Buffer): Precioish {
|
||||||
const dom = parseHTML(html);
|
const dom = parseHTML(html);
|
||||||
|
|
||||||
const ean = getEanFromText(dom);
|
const ean = getEanFromText(dom);
|
||||||
const precioCentavos = getPriceFromText(dom);
|
const precioCentavos = getPriceFromText(dom);
|
||||||
|
const inStock = getInStock(dom);
|
||||||
|
|
||||||
const name = dom.document
|
const name = dom.document
|
||||||
.querySelector("h1.product_page")
|
.querySelector("h1.product_page")
|
||||||
|
@ -40,5 +44,5 @@ export function getCotoProduct(html: string | Buffer): Precioish {
|
||||||
const imageUrl =
|
const imageUrl =
|
||||||
dom.document.querySelector<HTMLImageElement>(".zoom img")?.src;
|
dom.document.querySelector<HTMLImageElement>(".zoom img")?.src;
|
||||||
|
|
||||||
return { name, imageUrl, ean, precioCentavos };
|
return { name, imageUrl, ean, precioCentavos, inStock };
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue