-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
38 lines (32 loc) · 1.04 KB
/
bot.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
const updateBTCPrice = require('./methods/updateBTCPrice')
const formatCurrency = require('format-currency')
const twit = require('twit')
const Twitter = new twit({
consumer_key:process.env.CONSUMER_KEY,
consumer_secret:process.env.CONSUMER_SECRET,
access_token:process.env.ACCESS_TOKEN,
access_token_secret:process.env.ACCESS_TOKEN_SECRET
})
let price1
let price2
let avg
let opts = { format: '%s%v', locale: 'es-ES' }
let message = 'El precio del Bitcoin: '
let hashtags = ['#bitcoin','#elpreciodelbtc','#criptomonedas']
updateBTCPrice.BitcoinAverage()
.then(data => {
price1 = parseFloat(data)
updateBTCPrice.Coindesk()
.then(data => {
price2 = parseFloat(data)
avg = formatCurrency(((price1+price2)/2).toFixed(2))
let tweet = message+avg+'€ '+hashtags.join(" ")
Twitter.post('statuses/update', { status: tweet }, (err, data, response) => {
if (err) console.log(err)
if (response)
console.log('Tweet created! ==> ' + tweet + 'at: ' + new Date())
})
})
.catch(console.error)
})
.catch(console.error)