diff --git a/.drone.yml b/.drone.yml index 98d231f..af7b481 100644 --- a/.drone.yml +++ b/.drone.yml @@ -13,6 +13,9 @@ steps: commands: - cd /home/pi/warframe-market-bot - git pull +- name: install + commands: + - npm install - name: restart commands: - PM2_HOME='/home/pi/.pm2' pm2 restart warframe-market-bot diff --git a/.gitignore b/.gitignore index e971d13..923517c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,3 @@ node_modules .vscode -index.txt +index.html diff --git a/README.md b/README.md index 0b47566..09657ae 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,5 @@ +# Warframe Market Bot + Список Прайм предметов: https://warframe.fandom.com/wiki/Prime + Маркет: https://warframe.market diff --git a/index.js b/index.js index a78626a..f8bfbf0 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,8 @@ async function initPuppeteer (page) { } (async () => { - const browser = await puppeteer.launch({ executablePath: 'chromium-browser' }) + // const browser = await puppeteer.launch({ executablePath: 'chromium-browser' }) + const browser = await puppeteer.launch() const page = await browser.newPage() await initPuppeteer(page) @@ -26,11 +27,10 @@ async function initPuppeteer (page) { const setPrice = await item.set.getPrice(page) if (partsPrice < setPrice) { - output.addLine(`${item.name} prime: ${partsPrice}/${setPrice} выгода ${setPrice - partsPrice}`) + output.addItem(item.name, partsPrice, setPrice) } } await browser.close() - output.timestamp() output.submit() })() diff --git a/items/index.js b/items/index.js index 97940d2..bec1e70 100644 --- a/items/index.js +++ b/items/index.js @@ -18,9 +18,9 @@ const primaries = [ const items = [] -warframes.forEach((name) => { - items.push(new Warframe(name)) -}) +// warframes.forEach((name) => { +// items.push(new Warframe(name)) +// }) primaries.forEach((name) => { items.push(new Primary(name)) diff --git a/output.js b/output.js deleted file mode 100644 index 5402dcc..0000000 --- a/output.js +++ /dev/null @@ -1,29 +0,0 @@ -const fs = require('fs') - -class Output { - constructor () { - this.content = '' - } - - addLine (text) { - this.content += text + '\n' - } - - timestamp () { - this.addLine('\n' + new Date()) - } - - 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, 'utf-8') - } -} - -module.exports = new Output() diff --git a/output/OutputItem.js b/output/OutputItem.js new file mode 100644 index 0000000..4eb9872 --- /dev/null +++ b/output/OutputItem.js @@ -0,0 +1,9 @@ +module.exports = class OutputItem { + constructor (name, parts, set) { + this.name = name + ' prime' + this.parts = parts + this.set = set + + this.difference = set - parts + } +} diff --git a/output/index.js b/output/index.js new file mode 100644 index 0000000..1f9f3c8 --- /dev/null +++ b/output/index.js @@ -0,0 +1,39 @@ +const fs = require('fs') +const Handlebars = require('handlebars') +const OutputItem = require('./OutputItem') + +class Output { + constructor () { + this.items = [] + this.timestamp = null + } + + addItem (...p) { + this.items.push(new OutputItem(...p)) + } + + async compileTemplate () { + const templateFile = await fs.readFileSync('./output/template.hbs', 'utf8') + const template = Handlebars.compile(templateFile) + return template(this) + } + + async writeToFile (content) { + const filename = 'index.html' + + try { + await fs.unlinkSync(filename) + } catch { + console.log('File probably doesnt exist') + } + fs.writeFileSync(filename, content, 'utf-8') + } + + async submit () { + this.timestamp = new Date() + const content = await this.compileTemplate() + await this.writeToFile(content) + } +} + +module.exports = new Output() diff --git a/output/template.hbs b/output/template.hbs new file mode 100644 index 0000000..e14ac93 --- /dev/null +++ b/output/template.hbs @@ -0,0 +1,41 @@ + + + + + + + Warframe Market Gaps + + + + +

Warframe Market Gaps

+ + + +
+ Generated at {{timestamp}} +
+ + \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 6661e6e..f5222e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "version": "1.0.0", "license": "ISC", "dependencies": { + "handlebars": "^4.7.7", "puppeteer": "^13.3.2" }, "devDependencies": { @@ -1354,6 +1355,26 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/handlebars": { + "version": "4.7.7", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", + "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==", + "dependencies": { + "minimist": "^1.2.5", + "neo-async": "^2.6.0", + "source-map": "^0.6.1", + "wordwrap": "^1.0.0" + }, + "bin": { + "handlebars": "bin/handlebars" + }, + "engines": { + "node": ">=0.4.7" + }, + "optionalDependencies": { + "uglify-js": "^3.1.4" + } + }, "node_modules/has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -1840,9 +1861,7 @@ "node_modules/minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true, - "peer": true + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "node_modules/mkdirp-classic": { "version": "0.5.3", @@ -1861,6 +1880,11 @@ "dev": true, "peer": true }, + "node_modules/neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" + }, "node_modules/node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", @@ -2292,6 +2316,14 @@ "url": "https://github.com/chalk/slice-ansi?sponsor=1" } }, + "node_modules/source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -2535,6 +2567,18 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/uglify-js": { + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.15.1.tgz", + "integrity": "sha512-FAGKF12fWdkpvNJZENacOH0e/83eG6JyVQyanIJaBXCN1J11TUQv1T1/z8S+Z0CG0ZPk1nPcreF/c7lrTd0TEQ==", + "optional": true, + "bin": { + "uglifyjs": "bin/uglifyjs" + }, + "engines": { + "node": ">=0.8.0" + } + }, "node_modules/unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", @@ -2639,6 +2683,11 @@ "node": ">=0.10.0" } }, + "node_modules/wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=" + }, "node_modules/wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", @@ -3710,6 +3759,18 @@ "type-fest": "^0.20.2" } }, + "handlebars": { + "version": "4.7.7", + "resolved": "https://registry.npmjs.org/handlebars/-/handlebars-4.7.7.tgz", + "integrity": "sha512-aAcXm5OAfE/8IXkcZvCepKU3VzW1/39Fb5ZuqMtgI/hT8X2YgoMvBY5dLhq/cpOvw7Lk1nK/UF71aLG/ZnVYRA==", + "requires": { + "minimist": "^1.2.5", + "neo-async": "^2.6.0", + "source-map": "^0.6.1", + "uglify-js": "^3.1.4", + "wordwrap": "^1.0.0" + } + }, "has": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", @@ -4056,9 +4117,7 @@ "minimist": { "version": "1.2.5", "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.5.tgz", - "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==", - "dev": true, - "peer": true + "integrity": "sha512-FM9nNUYrRBAELZQT3xeZQ7fmMOBg6nWNmJKTcgsJeaLstP/UODVpGsr5OhXhhXg6f+qtJ8uiZ+PUxkDWcgIXLw==" }, "mkdirp-classic": { "version": "0.5.3", @@ -4077,6 +4136,11 @@ "dev": true, "peer": true }, + "neo-async": { + "version": "2.6.2", + "resolved": "https://registry.npmjs.org/neo-async/-/neo-async-2.6.2.tgz", + "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==" + }, "node-fetch": { "version": "2.6.7", "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", @@ -4374,6 +4438,11 @@ "is-fullwidth-code-point": "^3.0.0" } }, + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==" + }, "sprintf-js": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/sprintf-js/-/sprintf-js-1.0.3.tgz", @@ -4570,6 +4639,12 @@ "dev": true, "peer": true }, + "uglify-js": { + "version": "3.15.1", + "resolved": "https://registry.npmjs.org/uglify-js/-/uglify-js-3.15.1.tgz", + "integrity": "sha512-FAGKF12fWdkpvNJZENacOH0e/83eG6JyVQyanIJaBXCN1J11TUQv1T1/z8S+Z0CG0ZPk1nPcreF/c7lrTd0TEQ==", + "optional": true + }, "unbox-primitive": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.1.tgz", @@ -4659,6 +4734,11 @@ "dev": true, "peer": true }, + "wordwrap": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/wordwrap/-/wordwrap-1.0.0.tgz", + "integrity": "sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=" + }, "wrappy": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", diff --git a/package.json b/package.json index 19e5900..9502ee3 100644 --- a/package.json +++ b/package.json @@ -9,6 +9,7 @@ "author": "Anatoly Kopyl", "license": "ISC", "dependencies": { + "handlebars": "^4.7.7", "puppeteer": "^13.3.2" }, "devDependencies": {