Created
December 31, 2015 21:35
-
-
Save buckyball/dcf396a098ef2d0ee393 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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