Skip to content

Instantly share code, notes, and snippets.

@buckyball
Created December 31, 2015 21:35
Show Gist options
  • Save buckyball/dcf396a098ef2d0ee393 to your computer and use it in GitHub Desktop.
Save buckyball/dcf396a098ef2d0ee393 to your computer and use it in GitHub Desktop.
# Description:
# Find the latest Bitcoin price in specified currency
#
# Dependencies:
# "cheerio": ""
#
# Configuration:
# None
#
# Commands:
# hubot bitcoin price (in) <currency>
#
# Author:
# Sven Wegerhoff
module.exports = (robot) ->
robot.respond /bitcoin preis\s(in\s)?(.*)/i, (msg) ->
currency = msg.match[2].trim().toUpperCase()
bitcoinPrice(msg, currency)
bitcoinPrice = (msg, currency) ->
msg
.send "Looking up... sit tight..."
msg
.http("http://api.bitcoincharts.com/v1/weighted_prices.json")
.get() (err, res, body) ->
msg.send "#{getPrice(currency, body)}"
getPrice = (currency, data) ->
# "EUR": {"7d": "393.47", "30d": "386.27", "24h": "394.00"}
lastPrice = data[currency]["24h"]
highPrice = data[currency]["7d"]
lowPrice = data[currency]["30d"]
priceSymbol = null
if lastPrice == null
"Can't find the price for #{currency}. :("
else
"#{currency}: #{lastPrice} (7d: #{highPrice} | 30d: #{lowPrice})"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment