Part class

This commit is contained in:
2022-02-15 22:51:38 +03:00
parent efafcbc356
commit d47a4c634e
3 changed files with 23 additions and 8 deletions

View File

@@ -1,8 +1,5 @@
const puppeteer = require('puppeteer') const puppeteer = require('puppeteer')
const getPrice = require('./getPrice') const items = require('./items');
const items = require('./items')
const marketUrl = 'https://warframe.market/items/';
(async () => { (async () => {
const browser = await puppeteer.launch({ headless: false }) const browser = await puppeteer.launch({ headless: false })
@@ -11,10 +8,10 @@ const marketUrl = 'https://warframe.market/items/';
for (const item of items) { for (const item of items) {
let partsPrice = 0 let partsPrice = 0
for (const part of item.parts) { for (const part of item.parts) {
partsPrice += await getPrice(page, marketUrl + part.url) partsPrice += await part.getPrice(page)
} }
const setPrice = await getPrice(page, marketUrl + item.url) const setPrice = await item.set.getPrice(page)
if (partsPrice < setPrice) { if (partsPrice < setPrice) {
console.log(item.name, partsPrice, setPrice) console.log(item.name, partsPrice, setPrice)
} }

View File

@@ -1,12 +1,15 @@
const Part = require('./Part')
module.exports = class Item { module.exports = class Item {
constructor (name) { constructor (name) {
this.name = name this.name = name
this.url = `${this.name}_prime_set` this.set = new Part(name, 'set')
this.parts = [] this.parts = []
this.addPart('blueprint') this.addPart('blueprint')
} }
addPart (part) { addPart (part) {
this.parts.push({ part, url: `${this.name}_prime_${part}` }) this.parts.push(new Part(this.name, part))
} }
} }

15
items/Part.js Normal file
View File

@@ -0,0 +1,15 @@
module.exports = class Part {
constructor (set, part) {
this.part = part
this.url = `${set}_prime_${part}`
}
async getPrice (page) {
const marketUrl = 'https://warframe.market/items/'
await page.goto(marketUrl + this.url)
const element = await page.waitForSelector('b.price')
const value = await element.evaluate(el => el.textContent)
return Number(value)
}
}