Output to file
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,2 +1,3 @@
|
||||
node_modules
|
||||
.vscode
|
||||
index.txt
|
||||
|
||||
23
Output.js
Normal file
23
Output.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const fs = require('fs')
|
||||
|
||||
module.exports = class Output {
|
||||
constructor () {
|
||||
this.content = ''
|
||||
}
|
||||
|
||||
addLine (text) {
|
||||
this.content += text + '\n'
|
||||
}
|
||||
|
||||
submit () {
|
||||
const filename = 'index.txt'
|
||||
|
||||
try {
|
||||
fs.unlinkSync(filename)
|
||||
} catch (error) {
|
||||
console.error(error)
|
||||
console.log('File probably doesnt exist')
|
||||
}
|
||||
fs.writeFileSync(filename, this.content)
|
||||
}
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
module.exports = async function (page, url) {
|
||||
await page.goto(url)
|
||||
const element = await page.waitForSelector('b.price')
|
||||
const value = await element.evaluate(el => el.textContent)
|
||||
return Number(value)
|
||||
}
|
||||
7
index.js
7
index.js
@@ -1,5 +1,7 @@
|
||||
const puppeteer = require('puppeteer')
|
||||
const items = require('./items');
|
||||
const items = require('./items')
|
||||
const Output = require('./Output')
|
||||
const output = new Output();
|
||||
|
||||
(async () => {
|
||||
const browser = await puppeteer.launch({ headless: false })
|
||||
@@ -13,9 +15,10 @@ const items = require('./items');
|
||||
|
||||
const setPrice = await item.set.getPrice(page)
|
||||
if (partsPrice < setPrice) {
|
||||
console.log(item.name, partsPrice, setPrice)
|
||||
output.addLine(`${item.name} prime: ${partsPrice}/${setPrice} выгода ${setPrice - partsPrice}`)
|
||||
}
|
||||
}
|
||||
|
||||
await browser.close()
|
||||
output.submit()
|
||||
})()
|
||||
|
||||
@@ -9,7 +9,7 @@ module.exports = class Item {
|
||||
this.addPart('blueprint')
|
||||
}
|
||||
|
||||
addPart (part) {
|
||||
this.parts.push(new Part(this.name, part))
|
||||
addPart (part, amount) {
|
||||
this.parts.push(new Part(this.name, part, amount))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
module.exports = class Part {
|
||||
constructor (set, part) {
|
||||
constructor (set, part, amount) {
|
||||
this.part = part
|
||||
this.url = `${set}_prime_${part}`
|
||||
this.amount = amount ?? 1
|
||||
}
|
||||
|
||||
async getPrice (page) {
|
||||
@@ -10,6 +11,6 @@ module.exports = class Part {
|
||||
await page.goto(marketUrl + this.url)
|
||||
const element = await page.waitForSelector('b.price')
|
||||
const value = await element.evaluate(el => el.textContent)
|
||||
return Number(value)
|
||||
return Number(value) * this.amount
|
||||
}
|
||||
}
|
||||
|
||||
11
items/Primary.js
Normal file
11
items/Primary.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const Item = require('./Item')
|
||||
|
||||
module.exports = class Primary extends Item {
|
||||
constructor (name) {
|
||||
super(name)
|
||||
|
||||
this.addPart('barrel')
|
||||
this.addPart('receiver')
|
||||
this.addPart('stock')
|
||||
}
|
||||
}
|
||||
11
items/Secondary.js
Normal file
11
items/Secondary.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const Item = require('./Item')
|
||||
|
||||
module.exports = class Secondary extends Item {
|
||||
constructor (name) {
|
||||
super(name)
|
||||
|
||||
this.addPart('barrel', 2)
|
||||
this.addPart('receiver', 2)
|
||||
this.addPart('link')
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,29 @@
|
||||
const Warframe = require('./Warframe')
|
||||
const Primary = require('./Primary')
|
||||
// const Secondary = require('./Secondary')
|
||||
|
||||
module.exports = [
|
||||
new Warframe('ash'),
|
||||
new Warframe('atlas')
|
||||
const warframes = [
|
||||
'ash', 'atlas', 'banshee', 'chroma', 'ember',
|
||||
'equinox', 'frost', 'gara', 'harrow', 'hydroid',
|
||||
'inaros', 'ivara', 'limbo', 'loki', 'mag',
|
||||
'mesa', 'mirage', 'nekros', 'nezha', 'nidus',
|
||||
'nova', 'nyx', 'oberon', 'octavia', 'rhino',
|
||||
'saryn', 'titania', 'trinity', 'valkyr', 'vauban',
|
||||
'volt', 'wukong', 'zephyr'
|
||||
]
|
||||
|
||||
const primaries = [
|
||||
'astilla', 'baza', 'boar', 'boltor', 'braton'
|
||||
]
|
||||
|
||||
const items = []
|
||||
|
||||
warframes.forEach((name) => {
|
||||
items.push(new Warframe(name))
|
||||
})
|
||||
|
||||
primaries.forEach((name) => {
|
||||
items.push(new Primary(name))
|
||||
})
|
||||
|
||||
module.exports = items
|
||||
|
||||
Reference in New Issue
Block a user