Skip to content

Instantly share code, notes, and snippets.

@jesseadams
Created June 3, 2011 23:31
Show Gist options
  • Save jesseadams/1007364 to your computer and use it in GitHub Desktop.
Save jesseadams/1007364 to your computer and use it in GitHub Desktop.
Get weather info via Google's API
#!/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