weather plugin works now

This commit is contained in:
Akamaru 2015-06-08 21:30:07 +02:00
parent 9cb4440ab9
commit 7e825f7363

View File

@ -2,7 +2,6 @@ do
local BASE_URL = "http://api.openweathermap.org/data/2.5/weather" local BASE_URL = "http://api.openweathermap.org/data/2.5/weather"
local function get_weather(location) local function get_weather(location)
print("Finde Wetter in ", location) print("Finde Wetter in ", location)
local url = BASE_URL local url = BASE_URL
@ -15,11 +14,9 @@ local function get_weather(location)
local weather = json:decode(b) local weather = json:decode(b)
local city = weather.name local city = weather.name
local country = weather.sys.country 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 local temp = 'Die Temperatur in '..city
..' (' ..country..')' ..' (' ..country..')'
..' beträgt '..temperature..'°C' ..' beträgt '..weather.main.temp..'°C'
local conditions = 'Die aktuelle Wetterlage ist: ' local conditions = 'Die aktuelle Wetterlage ist: '
.. weather.weather[1].description .. weather.weather[1].description
@ -32,6 +29,7 @@ local function get_weather(location)
elseif weather.weather[1].main == 'Thunderstorm' then elseif weather.weather[1].main == 'Thunderstorm' then
conditions = conditions .. ' ☔☔☔☔' conditions = conditions .. ' ☔☔☔☔'
end end
return temp .. '\n' .. conditions return temp .. '\n' .. conditions
end end
@ -43,7 +41,7 @@ local function run(msg, matches)
end end
local text = get_weather(city) local text = get_weather(city)
if not text then if not text then
text = 'Konnte das Wetter von dieser Stadt nicht bekommen.' text = 'Konnte das Wetter dieser Stadt nicht bekommen.'
end end
return text return text
end end