Skip to content

Instantly share code, notes, and snippets.

@bhudgeons
Created July 12, 2012 22:06
Show Gist options
  • Save bhudgeons/3101404 to your computer and use it in GitHub Desktop.
Save bhudgeons/3101404 to your computer and use it in GitHub Desktop.
Wunderground Weather API Integration with Databinder-Dispatch
import dispatch._
import dispatch.liftjson.Js._
import net.liftweb.json.JsonAST.JString
final val APIKEY = "XXXXXXXXX" // get a free key at http://www.wunderground.com/weather/api/
def getTemp(city: String, state: String) = {
val http = new Http
val url = :/("api.wunderground.com") / "api" / APIKEY / "geolookup" / "conditions" / "q" / state / (city + ".json")
http(url ># { json =>
(json \\ "temperature_string") match {
case js: JString => js.values
case _ => "Not Available"
}
})
}
getTemp("Austin", "TX") // 93.4 F (34.1 C)
getTemp("San%20Francisco", "CA") // 66.6 F (19.2 C)
getTemp("Washington", "DC") // 84.4 F (29.1 C)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment