Created
June 3, 2011 23:31
-
-
Save jesseadams/1007364 to your computer and use it in GitHub Desktop.
Get weather info via Google's API
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
#!/usr/bin/env lua | |
local http = require("socket.http") | |
local zip_code = "60614" | |
-- Grab google weather data | |
url = "http://www.google.com/ig/api?weather=" .. zip_code | |
data = http.request(url) | |
-- Only snag current conditions | |
current = data:match("<current_conditions>(.-)</current_conditions>") | |
-- Data point config | |
data_points = { "condition", "temp_f" } | |
-- Parse! | |
values = {} | |
for key,name in ipairs(data_points) do | |
value = current:match('<' .. name ..' data="(.-)"/>') | |
values[name] = value | |
end | |
-- Use | |
print(values['temp_f']) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment