This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot/plugins/weather.lua
Akamaru 952271851e new plugins
kick.lua
pokedex.lua
router_status.lua
whereisip.lua
2015-05-23 16:37:42 +02:00

60 lines
1.5 KiB
Lua

do
local BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
local function get_weather(location)
print("Finde Wetter in ", location)
local url = BASE_URL
url = url..'?q='..location
url = url..'&lang=de&units=metric'
local b, c, h = http.request(url)
if c ~= 200 then return nil end
local weather = json:decode(b)
local city = weather.name
local country = weather.sys.country
local dot_temperature = round(weather.main.temp, 2)
local temperature = string.gsub(dot_temperature, "%.", "%,")
local temp = 'Die Temperatur in '..city
..' (' ..country..')'
..' beträgt '..temperature..'°C'
local conditions = 'Die aktuelle Wetterlage ist: '
.. weather.weather[1].description
if weather.weather[1].main == 'Clear' then
conditions = conditions .. ''
elseif weather.weather[1].main == 'Clouds' then
conditions = conditions .. ' ☁☁'
elseif weather.weather[1].main == 'Rain' then
conditions = conditions .. ''
elseif weather.weather[1].main == 'Thunderstorm' then
conditions = conditions .. ' ☔☔☔☔'
end
return temp .. '\n' .. conditions
end
local function run(msg, matches)
local city = 'Berlin'
if matches[1] ~= '/wetter' then
city = matches[1]
end
local text = get_weather(city)
if not text then
text = 'Konnte das Wetter von dieser Stadt nicht bekommen.'
end
return text
end
return {
description = "Wetter in dieser Stadt (Berlin ist Standard)",
usage = "/wetter (Stadt)",
patterns = {
"^/wetter$",
"^/wetter(.*)$"},
run = run
}
end