npm workspace integration

This commit is contained in:
2022-03-13 14:06:16 +03:00
parent 1e397af280
commit ff2cc92b5f
24 changed files with 14406 additions and 648 deletions

View File

@@ -1,8 +1,15 @@
require('dotenv').config()
const mongoose = require('mongoose')
const items = require('./items')
const output = require('./output');
const { models } = require('shared-stuff')
async function initDB () {
await mongoose.connect(process.env.MONGODB_URI)
}
(async () => {
await initDB()
for (const item of items) {
console.log(`Looking at ${item.name}`)
@@ -13,9 +20,12 @@ const output = require('./output');
const setPrice = await item.set.getPrice()
if (partsPrice < setPrice) {
output.addItem(item.name, partsPrice, setPrice)
const scanResult = new models.ScanResult({
name: item.name,
partsPrice,
setPrice
})
scanResult.save()
}
}
output.submit()
})()

View File

@@ -1,10 +0,0 @@
module.exports = class ListingSet {
constructor (name, parts, set) {
this.name = name + ' prime'
this.parts = parts
this.set = set
this.link = `https://warframe.market/items/${name}_prime_set`
this.difference = set - parts
}
}

View File

@@ -1,9 +0,0 @@
function ifEq (a, b, opts) {
if (a === b) {
return opts.fn(this)
} else {
return opts.inverse(this)
}
}
module.exports = { ifEq }

View File

@@ -1,35 +0,0 @@
{
"en": {
"link": "",
"title": "Market Gaps",
"description": "Find a profitable difference between the price of the set and the price of the sum of it's parts.",
"filter_by_difference": "Filter by difference:",
"name": "Name",
"parts_price": "Parts price",
"set_price": "Set price",
"difference": "Difference",
"generated_at": "Generated at"
},
"ru": {
"link": "ru",
"title": "Market Gaps",
"description": "Находите выгоду между покупкой сета по отдельности и продажей его в собранном виде.",
"filter_by_difference": "Фильтровать по разнице:",
"name": "Название",
"parts_price": "Стоимость частей",
"set_price": "Стоимость сета",
"difference": "Разница",
"generated_at": "Сгенерировано в"
},
"ua": {
"link": "ua",
"title": "Market Gaps",
"description": "Знаходьте вигоду між покупкою сета окремо та продажем його в зібраному вигляді.",
"filter_by_difference": "Фільтрувати за різницею:",
"name": "Назва",
"parts_price": "Вартість частин",
"set_price": "Вартість сета",
"difference": "Різниця",
"generated_at": "Згенеровано в"
}
}

View File

@@ -1,48 +0,0 @@
const fs = require('fs')
const Handlebars = require('handlebars')
const { ifEq } = require('./helpers')
const ListingSet = require('./ListingSet')
const i18n = require('./i18n.json')
Handlebars.registerHelper('if_eq', ifEq)
class Output {
constructor () {
this.items = []
this.timestamp = null
}
addItem (...p) {
this.items.push(new ListingSet(...p))
}
async _compileTemplate () {
const templateFile = await fs.readFileSync('./src/output/template.hbs', 'utf8')
return Handlebars.compile(templateFile)
}
async _writeToFile (filename, content) {
try {
await fs.unlinkSync(filename)
} catch {
console.log('File probably doesnt exist')
}
fs.writeFileSync(filename, content, 'utf8')
}
async submit () {
this.timestamp = new Date()
const template = await this._compileTemplate()
Object.keys(i18n).forEach(locale => {
const filename = i18n[locale].link || 'index'
this._writeToFile(`./public/${filename}.html`, template({
...this,
t: i18n[locale],
languages: i18n
}))
})
}
}
module.exports = new Output()

View File

@@ -1,102 +0,0 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Find profits in the Warframe market">
<meta name="keywords" content="warframe,market,buy,sell,trade,mod,blueprint,syndicate,relic,order,auction,riven,wts,wtb,sales,worth,platinum,price,checking">
<link rel="canonical" href="https://warframe.center/">
<link rel="alternate" hreflang="en" href="https://warframe.center/">
<link rel="alternate" hreflang="ru" href="https://warframe.center/ru/">
<link rel="alternate" hreflang="uk" href="https://warframe.center/ua/">
<link rel="alternate" hreflang="x-default" href="https://warframe.center/">
<meta property="og:title" content="Warframe Center">
<meta property="og:description" content="Find profits in the Warframe market">
<meta property="og:url" content="https://warframe.center">
<meta property="og:image" content="https://warframe.center/assets/warframe_logo.png">
<meta property="og:site_name" content="Warframe Center">
<meta property="og:locale" content="en">
<link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
<link rel="stylesheet" href="style.css">
<title>Warframe Center</title>
<!-- Yandex.Metrika counter -->
<script type="text/javascript" >
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
(window, document, "script", "https://mc.yandex.ru/metrika/tag.js", "ym");
ym(87671663, "init", {
clickmap:true,
trackLinks:true,
accurateTrackBounce:true
});
</script>
<noscript><div><img src="https://mc.yandex.ru/watch/87671663" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
<!-- /Yandex.Metrika counter -->
</head>
<body>
<div class="hero">
<img id="gunner1" src="./assets/gunner1.png">
<div class="main">
<img class="logo" src="./assets/warframe_logo.png">
<div class="text">
<h1>{{t.title}}</h1>
<p>{{t.description}}</p>
</div>
</div>
<img id="gunner2" src="./assets/gunner2.png">
<div class="languages">
{{#each languages}}
<a
href="/{{this.link}}"
class="{{#if_eq ../t.link this.link}}selected{{/if_eq}}"
>
<img src="./assets/languages/{{@key}}.png">
</a>
{{/each}}
</div>
</div>
<div class="main-column">
<div class="controls">
<label for="min-difference">{{t.filter_by_difference}}</label>
<input type="range" min="1" max="60" value="1" id="min-difference">
<span id="filter-value">1</span>
</div>
<table>
<thead>
<tr>
<th>{{t.name}}</th>
<th>{{t.parts_price}}</th>
<th>{{t.set_price}}</th>
<th>{{t.difference}}</th>
</tr>
</thead>
<tbody id="items">
{{#each items}}
<tr data-difference="{{this.difference}}">
<td class="name">
<a href="{{this.link}}" target="_blank">
{{this.name}}
</a>
</td>
<td>{{this.parts}}</td>
<td>{{this.set}}</td>
<td>{{this.difference}}</td>
</tr>
{{/each}}
</tbody>
</table>
</div>
<div class="timestamp">
{{t.generated_at}} {{timestamp}}
</div>
<script src="index.js"></script>
</body>
</html>