Open onotoleonide opened 9 years ago
For me OpenWeatherMap is ok, Weather Underground seems better but as you said an API key is required and that mess with initial configurations for everyone.
I actually made a modified version of weather.lua, I'll post it there just fyi
do
local BASE_URL = "http://api.wunderground.com/api/[YOUR_API_KEY]/conditions/q/"
local function get_weather(location)
print("Finding weather in ", location)
local url = BASE_URL..location..'.json'
local b, c, h = http.request(url)
if c ~= 200 then return nil end
local weather = json:decode(b)
if weather.response.results then
local i = 1
while weather.response.results[i] do
local cityforreal = "zmw:"..weather.response.results[i].zmw
get_weather(cityforreal)
i = i + 1
end
return
end
if weather.response.error then send_large_msg(thefuckingreceiver, "Not found") return end
local city = weather.current_observation.display_location.full
local country = weather.current_observation.display_location.country_iso3166
local temp = 'The temperature in '..city
..' (' ..country..')'
..' is '..weather.current_observation.temp_c..'°C'
local conditions = 'Current conditions are: '
.. weather.current_observation.weather
weather = nil
send_large_msg(thefuckingreceiver, temp .. '\n' .. conditions)
return
end
local function run(msg, matches)
local city = 'Madrid,ES'
thefuckingreceiver = get_receiver(msg)
if matches[1] ~= '!wund' then
city = matches[1]
end
get_weather(city)
end
return {
description = "weather in that city (Madrid is default)",
usage = "!wund (city)",
patterns = {
"^!wund$",
"^!wund (.*)$"
},
run = run
}
end
Maybe in another file?
yeah, my file is named wund.lua
Yeah, add this as a separate plugin. wund works better for me!
I don't know, OpenWeatherMap seems a bit inaccurate, Weather Underground has free API (requires key though).