-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.js
61 lines (50 loc) · 1.61 KB
/
dashboard.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict'
const fs = require('fs').promises
const https = require('https')
const Plotter = require('./src/Plotter.js')
const Writer = require('./src/Writer.js')
const Draw = require('./src/Draw.js')
const Graph = require('./src/Graph.js')
const config = require('./config')
const plotter = new Plotter()
const writer = new Writer(plotter)
const draw = new Draw(plotter)
async function run () {
const quoteFile = await fs.readFile(__dirname + '/storage/quotes', 'utf8')
const quotes = quoteFile.split('\n')
// Filter out long quotes
quotes.filter(function (quote) {
return quote.length < 60
})
const quote = quotes[Math.floor(Math.random() * quotes.length)]
await plotter.home()
await plotter.move(0, 500)
writer.setFontSize(config.writer.font.sizes.small)
await writer.write('Quote of the day:')
await writer.carriageReturn();
await writer.write(quote)
await writer.carriageReturn()
const graph = new Graph(plotter, 7400, 7600, async _ => {
return await getBitcoinPrice()
})
graph.width = 6000
graph.steps.total = 120
graph.steps.duration = 60
await graph.start()
await draw.drawPreset('ubuntu')
}
run()
async function getBitcoinPrice() {
return new Promise((resolve, reject) => {
https.get('https://api.coindesk.com/v1/bpi/currentprice.json', resp => {
let data = ''
resp.on('data', chunk => {
data += chunk
})
resp.on('end', _ => {
const json = JSON.parse(data)
resolve(json.bpi.GBP.rate_float)
})
})
})
}