Skip to content

Instantly share code, notes, and snippets.

@JerrySievert
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JerrySievert/914da7bf8d7f1cabc16c to your computer and use it in GitHub Desktop.
Save JerrySievert/914da7bf8d7f1cabc16c to your computer and use it in GitHub Desktop.
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