Last active
August 29, 2015 14:01
-
-
Save JerrySievert/914da7bf8d7f1cabc16c to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function(msg) { | |
if(/^hawthorne/.test(msg.message)) { | |
var match = msg.message.match(/^hawthorne\s+(.+)/); | |
var tap; | |
var taps = [ ]; | |
json = http.get("http://api.legitimatesounding.com/api/hawthorne"); | |
feed = JSON.parse(json); | |
// keep only the first 20 | |
var tmp = { }; | |
var keys = Object.keys(feed.data); | |
for (var i = 0; i < 20; i++) { | |
tmp[keys[i]] = feed.data[keys[i]]; | |
} | |
feed.data = tmp; | |
var tap_list = "Growlers Hawthorne (1-20): "; | |
if (match && feed.data[match[1]]) { | |
tap = feed.data[match[1]]; | |
return tap_list + "Tap " + match[1] + " - " + tap.brewery + " / " + tap.beer + " (" + tap.prices.join(", ") + ") " + parseInt(tap.fill*100) + "% full"; | |
} else { | |
for(var tap_id in feed.data) { | |
tap = feed.data[tap_id]; | |
if (match) { | |
if ((tap.beer && tap.beer.toUpperCase().match(match[1].toUpperCase())) || (tap.brewery && tap.brewery.toUpperCase().match(match[1].toUpperCase())) || (tap.style && tap.style.toUpperCase().match(match[1].toUpperCase()))) { | |
taps.push("Tap " + tap_id + " - " + tap.brewery + " / " + tap.beer + " (" + tap.prices.join(", ") + ") " + parseInt(tap.fill*100) + "% full"); | |
} | |
} else { | |
taps.push(tap_id + "-" + tap.beer); | |
} | |
} | |
} | |
if (taps.length === 0) { | |
tap_list += " none found"; | |
} else { | |
tap_list += taps.join(", "); | |
} | |
return tap_list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment