-- Lua Wetter App
--- (c) Tischi www.coolstream.to
+-- version 1.0 - 1.3 (c) by tischi
+-- version 1.4 by db2w-user
+-- version 1.5 Markham
-- Lizenz: GPL 2
--- Version: 1.2
--- Stand: 14.11.2014
+-- Stand: 2.11.2015
+-- V1.5 -- improve luaweatherapp
+-- V1.4 -- add. apikey thx. GetAway
+-- apikey shamelessly stolen from the source code of the page http://openweathermap.org/current
+
+-- Inputmethode hier angeben -- 0 fuer SMS; 1 fuer Keyboard
+KEYB=0;
+
+if KEYB == 1 then
+ inputmeth="keyboardinput"
+else
+ inputmeth="stringinput"
+end
--Eigenen Pfad ermitteln
function script_path()
end
--Variablen
+caption = "Wetter - Suche"
pfad=script_path() .. "LuaWetterApp/"
-txtpfad="/tmp/Lua_Wetter/"
-daten=txtpfad .. "luawetter.txt"
-datentxt=txtpfad .. "wetterdaten.txt"
-confPfad="/var/tuxbox/config/"
-confFile= confPfad .. "luawetterapp.conf"
-appicon="luawettericon.png"
-stadt_name={}
-stadt_name["name"]="Koeln"
-stadt_name["land"]="de"
+txtpfad = "/tmp/Lua_Wetter/"
+daten = txtpfad .. "luawetter.txt"
+datentxt = txtpfad .. "wetterdaten.txt"
+confPfad = "/var/tuxbox/config/"
+confFile = confPfad .. "luawetterapp.conf"
+configChanged = 0
+config_error = false
+
+wettericon=script_path() .. "luawettericon.png"
wochentag=os.date("%w")
wochentag2="0"
wochentag3="0"
wochentag4="0"
+
config = configfile.new()
conf={}
-conf["name"]="Koeln"
+conf["apikey"]="YOUR_APIKEY"
conf["farbe"]="COL.MENUCONTENT"
+conf["land"]="de"
+conf["name"]="Stadt"
conf["txtfarbe"]="COL.MENUCONTENT_TEXT"
+
hintfarbe=COL.MENUCONTENT
textfarbe=COL.MENUCONTENT_TEXT
local posix = require "posix"
--Ordner anlegen
os.execute("mkdir -p " .. txtpfad)
-os.execute("cp -f " .. script_path() .. "/" .. appicon .. " /share/tuxbox/neutrino/icons")
--Infofenster
function printinfo(t)
--zuordnung Wochentage
function wochentage()
-if wochentag == "0" then
- wochentag2="1"
- wochentag3="2"
- wochentag4="3"
-end
-if wochentag == "1" then
- wochentag2="2"
- wochentag3="3"
- wochentag4="4"
-end
-if wochentag == "2" then
- wochentag2="3"
- wochentag3="4"
- wochentag4="5"
-end
-if wochentag == "3" then
- wochentag2="4"
- wochentag3="5"
- wochentag4="6"
-end
-if wochentag == "4" then
- wochentag2="5"
- wochentag3="6"
- wochentag4="0"
-end
-if wochentag == "5" then
- wochentag2="6"
- wochentag3="0"
- wochentag4="1"
-end
-if wochentag == "6" then
- wochentag2="0"
- wochentag3="1"
- wochentag4="2"
-end
+wochentag2 = tostring((tonumber(wochentag) + 1) % 7)
+wochentag3 = tostring((tonumber(wochentag) + 2) % 7)
+wochentag4 = tostring((tonumber(wochentag) + 3) % 7)
end
--Wetterdaten holen und auslesen
wochentage()
local hb = hintbox.new{ title="Info", text="Daten werden geladen", icon="info", has_shadow=true, show_footer=false}
hb:paint()
- os.execute("wget -O " .. daten .. " -U Mozilla 'http://api.openweathermap.org/data/2.5/forecast/daily?q=" .. conf["name"] .. "&units=metric&cnt=4&lang=de'" )
+ os.execute("wget -O " .. daten .. " -U Mozilla 'http://api.openweathermap.org/data/2.5/forecast/daily?q=" .. conf["name"] .. "," .. conf["land"] .. "&units=metric&cnt=4&lang=" .. conf["land"] .. "&APPID=" .. conf["apikey"] .. "'" )
fp = io.open(daten, "r")
if fp == nil then
error("Kann nicht geladen werden: " .. daten)
--config laden
function loadConfig()
+ config_error = false
config:loadConfig(confFile)
+ conf["apikey"]= config:getString("apikey", "YOUR API KEY")
conf["farbe"] = config:getString("farbe", "COL.MENUCONTENT")
- conf["name"] = config:getString("name", "Koeln")
+ conf["land"] = config:getString("land", "de")
+ conf["name"] = config:getString("name", "Stadt")
conf["txtfarbe"] = config:getString("txtfarbe", "COL.MENUCONTENT_TEXT")
+
+ if string.len(conf["apikey"]) < 32 then
+ config_error = true
+ printinfo("Kein oder korrupter API-KEY!")
+ addMenue()
+ return
+ end
+
+ if string.len(conf["land"]) < 2 then
+ config_error = true
+ printinfo("Ungültiges Länderkürzel.")
+ addMenue()
+ return
+ end
+
+ if conf["name"] == "Stadt" or conf["name"] == "" then
+ printinfo("Bitte eine Stadt eingeben.")
+ config_error = true
+ addMenue()
+ return
+ end
end
--Funktion zum speichern der Config
if configChanged == 1 then
local h = hintbox.new{caption="Info", text="Einstellungen werden gespeichert...", icon="info", has_shadow=true, show_footer=false};
h:paint();
-
+
+ config:setString("apikey", conf["apikey"])
config:setString("farbe", conf["farbe"])
+ config:setString("land", conf["land"])
config:setString("name", conf["name"])
config:setString("txtfarbe", conf["txtfarbe"])
-
+
config:saveConfig(confFile)
configChanged = 0
end
end
---Farbvariablen zuordnen
+--Farbvariab zuordnen
function farbAuswahl()
if conf["farbe"] == "weiss" then
hintfarbe=COL.WHITE
--Wetterdaten anzeigen im Fenster
function anzeigepaint()
- count = 1
- while count <= 16 do
- anz[count]:paint()
- count = count + 1
+ for i=1,16 do
+ anz[i]:paint()
end
end
--Wetterdaten verbergen
function anzeigehide()
- count = 1
- while count <= 16 do
- anz[count]:hide{no_restore=true}
- count = count + 1
+ for i=16,1,-1 do
+ anz[i]:hide{no_restore=true}
end
end
function wetterfenster()
wochentage()
anz={}
-local dx = (SCREEN.END_X - SCREEN.OFF_X) / 2
-local dy = (SCREEN.END_Y - SCREEN.OFF_Y) / 2
+
+local dx = (SCREEN.END_X - SCREEN.OFF_X) / 2 + 10
+local dy = (SCREEN.END_Y - SCREEN.OFF_Y) / 2 + 10
local x = SCREEN.OFF_X
local y = SCREEN.OFF_Y
local xx = SCREEN.END_X
local yy = SCREEN.END_Y
-anz[16]=ctext.new{parent=w, x=dx-200, y=y+30, dx=450, dy=30, text=lines[20], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU_TITLE'], mode="ALIGN_CENTER" }
+anz[5]=ctext.new{parent=w, x=xx-280, y=yy-50, dx=200, dy=20, text="Stadt-PLZ", color_body=0xFF, color_text=COL['WHITE'], font_text=FONT['MENU'], mode="ALIGN_LEFT" }
+anz[4]=ctext.new{parent=w, x=dx-200, y=y+30, dx=450, dy=30, text=lines[20], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU_TITLE'], mode="ALIGN_CENTER" }
anz[3]=ctext.new{parent=w, x=dx-200, y=y+188, dx=450, dy=175, text=lines[4] .. "\n" .. lines[5] .. "\n" .. lines[6] .. "\n" .. lines[7], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
anz[2]=ctext.new{parent=w, x=dx-73, y=y+60, dx=323, dy=128, text="Heute: " .. lines[1] .. "\n" .. lines[3], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
anz[1]=cpicture.new{parent=w, x=dx-200, y=y+60 , dx=128, dy=128, image=pfad .. lines[2] .. ".png", transparency=2, color_background=hintfarbe, mode="ALIGN_RIGHT"}
-anz[4]=cpicture.new{parent=w, x=dx-562, y=yy-248 , dx=128, dy=128, image=pfad .. lines[9] .. ".png", transparency=2, color_background=hintfarbe, mode="ALIGN_RIGHT"}
-anz[5]=ctext.new{parent=w, x=dx-434, y=yy-248, dx=250, dy=128, text=lines[8] .. "\n" .. lines[10], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
-anz[10]=ctext.new{parent=w, x=dx-562, y=yy-120, dx=378, dy=50, text=lines[11], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
+anz[6]=cpicture.new{parent=w, x=dx-562, y=yy-248 , dx=128, dy=128, image=pfad .. lines[9] .. ".png", transparency=2, color_background=hintfarbe, mode="ALIGN_RIGHT"}
+anz[7]=ctext.new{parent=w, x=dx-434, y=yy-248, dx=250, dy=128, text=lines[8] .. "\n" .. lines[10], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
+anz[12]=ctext.new{parent=w, x=dx-562, y=yy-120, dx=378, dy=50, text=lines[11], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
-anz[6]=cpicture.new{parent=w, x=dx-164, y=yy-248 , dx=128, dy=128, image=pfad .. lines[13] .. ".png", transparency=2, color_background=hintfarbe, mode="ALIGN_RIGHT"}
-anz[7]=ctext.new{parent=w, x=dx-36, y=yy-248, dx=250, dy=128, text=lines[12] .. "\n" .. lines[14], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
-anz[11]=ctext.new{parent=w, x=dx-164, y=yy-120, dx=378, dy=50, text=lines[15], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
+anz[8]=cpicture.new{parent=w, x=dx-164, y=yy-248 , dx=128, dy=128, image=pfad .. lines[13] .. ".png", transparency=2, color_background=hintfarbe, mode="ALIGN_RIGHT"}
+anz[9]=ctext.new{parent=w, x=dx-36, y=yy-248, dx=250, dy=128, text=lines[12] .. "\n" .. lines[14], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
+anz[13]=ctext.new{parent=w, x=dx-164, y=yy-120, dx=378, dy=50, text=lines[15], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
-anz[8]=cpicture.new{parent=w, x=dx+234, y=yy-248 , dx=128, dy=128, image=pfad .. lines[17] .. ".png", transparency=2, color_background=hintfarbe, mode="ALIGN_RIGHT"}
-anz[9]=ctext.new{parent=w, x=dx+362, y=yy-248, dx=250, dy=128, text=lines[16] .. "\n" .. lines[18], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
-anz[12]=ctext.new{parent=w, x=dx+234, y=yy-120, dx=378, dy=50, text=lines[19], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
+anz[10]=cpicture.new{parent=w, x=dx+234, y=yy-248 , dx=128, dy=128, image=pfad .. lines[17] .. ".png", transparency=2, color_background=hintfarbe, mode="ALIGN_RIGHT" }
+anz[11]=ctext.new{parent=w, x=dx+362, y=yy-248, dx=250, dy=128, text=lines[16] .. "\n" .. lines[18], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
+anz[14]=ctext.new{parent=w, x=dx+234, y=yy-120, dx=378, dy=50, text=lines[19], color_body=hintfarbe, color_text=textfarbe, font_text=FONT['MENU'], mode="ALIGN_CENTER" }
-anz[13]=ctext.new{parent=w, x=x+100, y=yy-50, dx=400, dy=20, text="www.openweathermap.org", color_body=0xFF, color_text=COL['WHITE'], font_text=FONT['MENU'], mode="ALIGN_CENTER" }
-anz[14]=cpicture.new{parent=w, x=xx-310, y=yy-45 , dx=20, dy=10, image="menu", transparency=2, color_background=0xFF, mode="ALIGN_RIGHT"}
-anz[15]=ctext.new{parent=w, x=xx-280, y=yy-50, dx=200, dy=20, text="Stadt-PLZ", color_body=0xFF, color_text=COL['WHITE'], font_text=FONT['MENU'], mode="ALIGN_LEFT" }
+anz[15]=ctext.new{parent=w, x=x+100, y=yy-50, dx=400, dy=20, text="www.openweathermap.org", color_body=0xFF, color_text=COL['WHITE'], font_text=FONT['MENU'], mode="ALIGN_CENTER" }
+anz[16]=cpicture.new{parent=w, x=xx-310, y=yy-45 , dx=20, dy=10, image="menu", transparency=2, color_background=0xFF, mode="ALIGN_RIGHT"}
anzeigepaint()
if (msg == RC['setup']) then
anzeigehide()
addMenue()
+ start()
end
until msg == RC['home']
anzeigehide()
beenden()
end
---Prüfen ob Pluginverezechnis existiert
+--Prüfen ob Pluginverzeichnis existiert
function FolderExists()
local fileHandle, strError = io.open(pfad .. "01d.png", "r")
if fileHandle ~= nil then
end
function handle_key(a)
- if (confChanged == 0) then return MENU_RETURN.EXIT end
+ if (configChanged == 0 or config_error == true) then return MENU_RETURN.EXIT end
local res = messagebox.exec{title="Änderungen verwerfen?", text="Sollen die Änderungen verworfen werden?", buttons={ "yes", "no" }, has_shadow=true }
if (res == "yes") then return MENU_RETURN.EXIT end
return MENU_RETURN.EXIT_REPAINT
end
---Menü anzeigen
+--Menüanzeigen
function addMenue()
- local m = menu.new{name="Wetter - Suche", has_shadow=true}
+ local m = menu.new{name=caption, icon=wettericon, has_shadow=true, mwidth=50}
m:addKey{directkey = RC["home"], id = "home", action = "handle_key"}
m:addItem{type = "back"}
m:addItem{type="separatorline"}
- m:addItem{type="stringinput", action="set_string", id="name", value=conf["name"], sms=1, name="PLZ oder Name", directkey=RC["1"]}
+ m:addItem{type=inputmeth, action="set_string", id="name", value=conf["name"], sms=1, name="PLZ oder Name", directkey=RC["1"]}
+ m:addItem{type=inputmeth, size=20, action="set_string", id="land", value=conf["land"], sms=1, name="Land (de oder germany)", directkey=RC["2"]}
+ m:addItem{type="separatorline"}
+ m:addItem{type="chooser", action="set_string", options={"Theme-Farbe", "weiss", "schwarz", "grau", "rot", "grün", "blau", "gelb"}, id="farbe", value=conf["farbe"], name="Hintergrundfarbe", directkey=RC["3"]}
+ m:addItem{type="chooser", action="set_string", options={"Theme-Farbe", "weiss", "schwarz", "grau", "rot", "grün", "blau", "gelb"}, id="txtfarbe", value=conf["txtfarbe"], name="Textfarbe", directkey=RC["4"]}
m:addItem{type="separatorline"}
- m:addItem{type="chooser", action="set_string", options={"Theme-Farbe", "weiss", "schwarz", "grau", "rot", "grün", "blau", "gelb"}, id="farbe", value=conf["farbe"], name="Hintergrundfarbe", directkey=RC["2"]}
- m:addItem{type="chooser", action="set_string", options={"Theme-Farbe", "weiss", "schwarz", "grau", "rot", "grün", "blau", "gelb"}, id="txtfarbe", value=conf["txtfarbe"], name="Textfarbe", directkey=RC["3"]}
+ m:addItem{type=inputmeth, size=32, action="set_string", id="apikey", value=conf["apikey"], sms=1, name="API-Key", directkey=RC["5"]}
m:addItem{type="separatorline"}
m:addItem{type="forwarder", name="Speichern", action="saveConfig", icon="rot", directkey=RC["red"]}
m:exec()
+end
+
+function start()
+ FolderExists()
loadConfig()
- get_weather()
farbAuswahl()
- wetterfenster()
+ if config_error == false then
+ get_weather()
+ wetterfenster()
+ end
end
-FolderExists()
-loadConfig()
-farbAuswahl()
-get_weather()
-wetterfenster()
\ No newline at end of file
+start()