integration of authentication
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
// Interencheres.js
|
||||
'use strict';
|
||||
const { config } = require('../../../config');
|
||||
const {Scraper} = require('../Scraper');
|
||||
const DrouotData = require('./DrouotData');
|
||||
|
||||
@@ -131,6 +132,8 @@ class Drouot extends Scraper {
|
||||
// askStop : sale is followed by the AuctionAgent and the user ask to stop following
|
||||
// pause : the Sale is stopped by the Auction House and ready to restart
|
||||
// end : the Sale is ended
|
||||
// endOnError : the Sale is ended on error
|
||||
// endOnRequest: end of follow asked by user
|
||||
|
||||
let status = 'ready'
|
||||
|
||||
@@ -258,6 +261,9 @@ class Drouot extends Scraper {
|
||||
|
||||
page = await this.CheckAndConnect(page);
|
||||
|
||||
let lastbid = 0;
|
||||
let CloseCount = 0;
|
||||
|
||||
//init Protobuf Decoder
|
||||
const protobuf = require("protobufjs");
|
||||
const root = await protobuf.load(this._PATH_PROTOBUF_FILE);
|
||||
@@ -278,7 +284,6 @@ class Drouot extends Scraper {
|
||||
if(BideMessage.vente && BideMessage.vente.lot && BideMessage.vente.lot.lotId != undefined){
|
||||
DataLot = await this.platformData.getLiveDataLot(BideMessage.vente.lot.lotId);
|
||||
}
|
||||
//console.log('BideMessage Type: '+BideMessage.type+' Lot: '+BideMessage.vente.lot.lotId);
|
||||
|
||||
switch (BideMessage.type) {
|
||||
case 'PING':
|
||||
@@ -287,16 +292,31 @@ class Drouot extends Scraper {
|
||||
break;
|
||||
case 'INIT':
|
||||
console.log('INIT');
|
||||
|
||||
break;
|
||||
case 'CLOSE':
|
||||
|
||||
case 'CLOSE':
|
||||
console.log('CLOSE');
|
||||
|
||||
//refresh the live to avoid unintoended close
|
||||
clearInterval(CheckAskStop);
|
||||
CloseCount++;
|
||||
|
||||
if(CloseCount > config.agent.maxCloseWebsockets){
|
||||
console.log('CloseCount > config.agent.maxCloseWebsockets')
|
||||
StopLive('endOnError')
|
||||
return
|
||||
}else{
|
||||
console.log('Retry #'+CloseCount)
|
||||
await GoLive();
|
||||
}
|
||||
|
||||
break;
|
||||
case 'BID':
|
||||
console.log('BID');
|
||||
console.log('Lot: '+BideMessage.vente.lot.lotId+' Amount: '+BideMessage.vente.bid.amount);
|
||||
|
||||
|
||||
lastbid = Date.now();
|
||||
|
||||
await this.JucundusBid(
|
||||
BideMessage.vente.lot.lotId,
|
||||
Date.now(),
|
||||
@@ -392,61 +412,91 @@ class Drouot extends Scraper {
|
||||
//console.log('Unknown type:', BideMessage);
|
||||
}
|
||||
|
||||
};
|
||||
};
|
||||
|
||||
let CheckAskStop = null;
|
||||
let CheckLastBid = null;
|
||||
let Socket = null;
|
||||
|
||||
// Stop the Live
|
||||
const StopLive = async (code) => {
|
||||
clearInterval(CheckAskStop);
|
||||
clearInterval(CheckLastBid);
|
||||
|
||||
await this.JucundusEndSale(code)
|
||||
|
||||
page.close()
|
||||
browser.close()
|
||||
}
|
||||
|
||||
return
|
||||
|
||||
// create the live URL
|
||||
let {saleID} = await this.platformData.getUrlInfo(this.Url);
|
||||
let UrlLive = this._PAGE_MAIN + "live/bidlive/" + saleID;
|
||||
|
||||
let CheckAskStop = null;
|
||||
let Socket = null;
|
||||
|
||||
// Stop the Live
|
||||
const StopLive = async (params) => {
|
||||
clearInterval(CheckAskStop);
|
||||
page.close()
|
||||
browser.close()
|
||||
const GoLive = async () => {
|
||||
try{
|
||||
console.log('UrlLive : '+UrlLive)
|
||||
|
||||
await page.goto(UrlLive, { waitUntil: 'domcontentloaded' });
|
||||
|
||||
// intercept Lots Data
|
||||
await page.route('https://api.drouot.com/drouot/gingolem/api/live/venteInfos/'+saleID+'?lang=fr', async route => {
|
||||
console.log('GetLiveData')
|
||||
const response = await route.fetch();
|
||||
const LotData = await response.json();
|
||||
this.platformData.setLiveData(LotData.data);
|
||||
route.continue();
|
||||
});
|
||||
|
||||
page.on('websocket', ws => {
|
||||
Socket = ws;
|
||||
Socket.on('framereceived', listener);
|
||||
console.log('Websocket connected');
|
||||
});
|
||||
|
||||
console.log('UrlLive : reload')
|
||||
await page.reload();
|
||||
|
||||
// check if stop was asked
|
||||
CheckAskStop = setInterval(async () => {
|
||||
this.JucundusCheckStop()
|
||||
.then(async AskStop => {
|
||||
if(AskStop){
|
||||
await StopLive('endOnRequest')
|
||||
return
|
||||
}
|
||||
})
|
||||
}, 10000); // 10000 milliseconds = 10 seconds
|
||||
|
||||
// Check every minute if the last event is more than 10 minutes ago
|
||||
CheckLastBid = setInterval(() => {
|
||||
if (lastbid && Date.now() - lastbid > 10 * 60 * 1000) {
|
||||
console.log("More than 10 minutes since the last bid.");
|
||||
this.JucundusSetSaleStatus(saleInfo, 'end')
|
||||
(async () => {
|
||||
await StopLive('end');
|
||||
})();
|
||||
return
|
||||
}
|
||||
}, 60 * 1000); // 60 seconds = 1 minute
|
||||
|
||||
}catch(e){
|
||||
console.log('Error : '+e)
|
||||
throw new Error('Error: '+e)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try{
|
||||
console.log('UrlLive : '+UrlLive)
|
||||
await GoLive();
|
||||
|
||||
await page.goto(UrlLive, { waitUntil: 'domcontentloaded' });
|
||||
|
||||
// intercept Lots Data
|
||||
await page.route('https://api.drouot.com/drouot/gingolem/api/live/venteInfos/'+saleID+'?lang=fr', async route => {
|
||||
console.log('GetLiveData')
|
||||
const response = await route.fetch();
|
||||
const LotData = await response.json();
|
||||
this.platformData.setLiveData(LotData.data);
|
||||
route.continue();
|
||||
});
|
||||
}
|
||||
|
||||
page.on('websocket', ws => {
|
||||
Socket = ws;
|
||||
Socket.on('framereceived', listener);
|
||||
console.log('Websocket connected');
|
||||
});
|
||||
|
||||
console.log('UrlLive : reload')
|
||||
await page.reload();
|
||||
|
||||
// check if stop was asked
|
||||
CheckAskStop = setInterval(async () => {
|
||||
this.JucundusCheckStop()
|
||||
.then(AskStop => {
|
||||
if(AskStop){
|
||||
StopLive()
|
||||
}
|
||||
})
|
||||
}, 10000); // 10000 milliseconds = 10 seconds
|
||||
|
||||
}catch(e){
|
||||
console.log('Error : '+e)
|
||||
throw new Error('Error: '+e)
|
||||
}
|
||||
CaptureVideo = async () => {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
module.exports = Drouot
|
||||
@@ -344,9 +344,35 @@ class DrouotData extends ScraperTools {
|
||||
SaleDateString = SaleDateString.trim()
|
||||
|
||||
let cleanStr = SaleDateString.replace(/\\s|\\n/g, ' ').replace(/\s+/g, ' ');
|
||||
|
||||
SaleDate = moment.tz(cleanStr, 'dddd D MMMM à HH:mm (z)', 'fr', 'Europe/Paris').format();
|
||||
|
||||
// Extract the timezone abbreviation
|
||||
const timezoneAbbrMatch = cleanStr.match(/\(([^)]+)\)$/);
|
||||
let timezoneAbbr = timezoneAbbrMatch ? timezoneAbbrMatch[1] : null;
|
||||
|
||||
// Map of common timezone abbreviations to full timezone names
|
||||
const timezoneMap = {
|
||||
'BST': 'Europe/London',
|
||||
'CET': 'Europe/Paris',
|
||||
'CEST': 'Europe/Paris',
|
||||
'EDT': 'America/New_York',
|
||||
'EST': 'America/New_York',
|
||||
'PST': 'America/Los_Angeles',
|
||||
'CDT': 'America/Chicago',
|
||||
// Add more as needed
|
||||
};
|
||||
// Replace the abbreviation with the full timezone name if it exists in the map
|
||||
if (timezoneAbbr && timezoneMap[timezoneAbbr]) {
|
||||
cleanStr = cleanStr.replace(`(${timezoneAbbr})`, timezoneMap[timezoneAbbr]);
|
||||
}
|
||||
|
||||
console.log('cleanStr : '+cleanStr)
|
||||
|
||||
// Parse the date string with the correct format and timezone
|
||||
let saleDate = moment.tz(cleanStr, 'dddd D MMMM à HH:mm z', 'fr', timezoneMap[timezoneAbbr] || 'UTC');
|
||||
|
||||
// Convert to the desired timezone "Europe/Paris"
|
||||
SaleDate = saleDate.tz('Europe/Paris').format();
|
||||
|
||||
// Live Sale
|
||||
}else{
|
||||
SaleDate = moment.tz('Europe/Paris').format();
|
||||
|
||||
Reference in New Issue
Block a user