Is it Cold Enough for Beer Outside?

As winter releases its grip on the northern hemisphere, and things begin to chill down south, you may be wondering: Can I store my beer outside? Because, if your fridge is anything like mine, there's too much food in there for more than a six pack of beer. Ideally, I would like to keep it on the back porch.

I like single-purpose sites. Even better is if the code is small enough to demo in a training class. Inspired by Is it a Jewish Holiday Today, I created http://coldout.beer

ColdOut.beer uses the Weather Underground API. The API is a nice choice for teaching API requests for two reasons:

  • it can be accessed by GET requests.
  • the API key can simply be included in the URL or querystring

For deploying the site, Aerobatic was indispensible. First off, publishing the site via git push is dead simple - something I can handle while lecturing to the class. More importantly, the HTTP Proxy allows me to keep with Wunderground API key secure. Third, having easy staging sites lets me prototype ideas while lecturing, and deploy them for the class to see. Finally, the free SSL certificates give the site a professional feel.

How does the code work? It's a simple jQuery GET request:

// this URL is set up by the Aerobatic HTTP Proxy
$.get('/api', updater);

function updater(data) {  
  var temp_f = data.current_observation.temp_f;
  var coldEnough = temp_f <= 46;

  if (coldEnough) {
    $('h2.answer').text('🍺 HELL YEAH!');
  } else {
    $('h2.answer').text('🌴 No way, José. It\'s only ' + temp_f + 'degrees.');
  }
  $('span.location').text(data.current_observation.display_location.full)
}

Some things I could do to improve the site (and happy to accept pull requests) are:

  • Temperature conversion to degrees Celsius. After all, most of the world uses it!
  • Use browser geolocation for a more precise location

Go check out the code and Aerobatic documentation to see how all the features come together, stay cool, chill your beer, and spread the word!

Photo by waitscm - http://flic.kr/p/avT1bH

Ivan Storck

Web Developer, Teacher, Entrepreneur. Co-founder of Sustainable Websites, Code Fellows, and Aerobatic. Ivan lives in Seattle and enjoys paddling his SUP, spending time with family, and traveling.