Created
July 12, 2012 22:06
-
-
Save bhudgeons/3101404 to your computer and use it in GitHub Desktop.
Wunderground Weather API Integration with Databinder-Dispatch
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
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