S
Size: a a a
S
В
PP
PP
R
OS
OS
R
v
S
v
v
R
R
S
S
R
S
R
init(job) {
this.getItems()
.pipe(
tap(() => job.stop()),
pluck("data"),
map((items: Product[]) => items.filter(item => item["watch"] == true && !!item["market_url"])),
tap(console.log),
concat(items => items
.filter(item => !!item["watch"])
.map(item => this.seleniumService.getPrice(item, job)).pipe(toArray())
)
).subscribe((products: Product[]) => {
products
.filter(item => !!item)
.map(product => {
console.log('prod: ', product);
let price = this.priceCheckerService.checkPrice(product.price_step, +product.variants[0].price, +product.secPrice, +product.min_price);
if (price.needUpdate && product.secondPositionShop != this.storeId) {
this.updatePrice(product, price.newPrice);
}
});
job.start()
});
}
async getPrice(item, job) {
// const options = new Options().addArguments('-profile', '/home/seluser/.mozilla/firefox/31970d0t.zukazuka2');
const driver = await new Builder()
.forBrowser("firefox")
.usingServer('http://localhost:4444/wd/hub')
// .setFirefoxOptions(options)
.build();
try {
await driver.get(item["market_url"]);
const element = await driver.findElements(
By.css(".n-snippet-list .snippet-card")
);
if (element.length) {
await driver.wait(until.elementIsVisible(element[1]), 500);
const data = await element[1].getAttribute("data-bem");
await driver.quit();
item["secPrice"] = JSON.parse(data)["shop-history"]["clickParams"]["price"];
item["secondPositionShop"]= JSON.parse(data)["shop-history"]["clickParams"]["store"];
return item;
}
} catch (e) {
this.logger.alert(e);
job.start()
} finally {
// await driver.quit();
}
}
S