From 9320eb8b95ab0725b92b84ea7df2676f02c4d912 Mon Sep 17 00:00:00 2001 From: Admin Date: Sat, 6 Dec 2025 07:58:18 +0700 Subject: [PATCH] update grays get current price --- .../models/grays.com/grays-product-bid.js | 46 ++++++++++++++----- auto-bid-tool/system/utils.js | 2 + 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/auto-bid-tool/models/grays.com/grays-product-bid.js b/auto-bid-tool/models/grays.com/grays-product-bid.js index ea714f4..d602a97 100644 --- a/auto-bid-tool/models/grays.com/grays-product-bid.js +++ b/auto-bid-tool/models/grays.com/grays-product-bid.js @@ -250,18 +250,26 @@ export class GraysProductBid extends ProductBid { .$eval(".dls-heading-3.lotPageTitle", (el) => el.innerText) .catch(() => null); - await page - .waitForSelector( - "#biddableLot > form > div > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div > span > span", - { timeout: 5000 } - ) - .catch(() => null); - const current_price = await page - .$eval( - "#biddableLot > form > div > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div > span > span", - (el) => el.innerText - ) - .catch(() => null); + let current_price = null; + + const apiCurrentPrice = await this.getCurrentPrice(); + + if (!apiCurrentPrice) { + await page + .waitForSelector( + "#biddableLot > form > div > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div > span > span", + { timeout: 5000 } + ) + .catch(() => null); + current_price = await page + .$eval( + "#biddableLot > form > div > div:nth-child(1) > div:nth-child(1) > div:nth-child(2) > div > span > span", + (el) => el.innerText + ) + .catch(() => null); + } else { + current_price = apiCurrentPrice; + } console.log( `📌 [${this.id}] Product Info: Lot ID: ${lot_id}, Name: ${name}, Current Price: ${current_price}, Reserve price: ${price_value}` @@ -278,6 +286,8 @@ export class GraysProductBid extends ProductBid { ["close_time"] ); + console.log(data); + this.handleUpdateBid(data); return { price_value, lot_id, name, current_price }; @@ -497,6 +507,18 @@ export class GraysProductBid extends ProductBid { return data; } + async getCurrentPrice() { + const data = await this.getCurrentHistories(); + + if (!data || data?.length <= 0) return null; + + const first = data[0]; + + if (!first) return null; + + return first?.Price || null; + } + getBidedData() { return global[`BIDED_DATA_${this.web_bid?.origin_url}`]; } diff --git a/auto-bid-tool/system/utils.js b/auto-bid-tool/system/utils.js index 0c4e2d0..f1c5165 100644 --- a/auto-bid-tool/system/utils.js +++ b/auto-bid-tool/system/utils.js @@ -126,6 +126,8 @@ export function isTimeReached(targetTime) { } export function extractNumber(str) { + if (typeof str === "number") return str; + const match = str.match(/\d+(\.\d+)?/); return match ? parseFloat(match[0]) : null; }