--[[ Heizölpreise Plugin lua v0.5 Copyright (C) 2018, Jacek Jendrzej 'satbaby' License: GPL This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. ]] local hop={} local top={} n = neutrino() local FontMenu = FONT.MENU local FontTitle = FONT.MENU_TITLE local conf = {} function loadConfig() local Nconfig = configfile.new() Nconfig:loadConfig("/var/tuxbox/config/neutrino.conf") conf.corner_on = Nconfig:getInt32("rounded_corners", 0) conf.corner_large = 0 conf.corner_top = 0 conf.corner_bottom = 0 conf.select = 0 if conf.corner_on then conf.corner_large = CORNER.RADIUS_LARGE conf.corner_top = (CORNER.TOP_LEFT + CORNER.TOP_RIGHT) conf.corner_bottom = (CORNER.BOTTOM_LEFT + CORNER.BOTTOM_RIGHT) end end -- character table string local b='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/' -- decode function dec(data) data = string.gsub(data, '[^'..b..'=]', '') return (data:gsub('.', function(x) if (x == '=') then return '' end local r,f='',(b:find(x)-1) for i=6,1,-1 do r=r..(f%2^i-f%2^(i-1)>0 and '1' or '0') end return r; end):gsub('%d%d%d?%d?%d?%d?%d?%d?', function(x) if (#x ~= 8) then return '' end local c=0 for i=1,8 do c=c+(x:sub(i,i)=='1' and 2^(8-i) or 0) end return string.char(c) end)) end function decodeImage(b64Image) local imgTyp = b64Image:match("data:image/(.-);base64,") local repData = "data:image/" .. imgTyp .. ";base64," local b64Data = string.gsub(b64Image, repData, ""); local tmpImg = os.tmpname() local retImg = tmpImg .. "." .. imgTyp local f = io.open(retImg, "w+") f:write(dec(b64Data)) f:close() os.remove(tmpImg) return retImg end function getdata(Url,outputfile) if Url == nil then return nil end if Curl == nil then Curl = curl.new() end if Url:sub(1, 2) == '//' then Url = 'http:' .. Url end local ret, data = Curl:download{url=Url,A="Mozilla/5.0;",maxRedirs=5,followRedir=true,o=outputfile } if ret == CURL.OK then if outputfile then return 1 end return data else return nil end end function make_tab(tab,data,patern,count) local k = 0 for td in data:gmatch("<" .. patern ..".->(.-)") do local aa= td:match('
(.-)
%c+') if aa then for div in aa:gmatch("(.-)") do local charturl = div:match'' if charturl or (patern == "th" and count == 0) then count = count + 1 tab[count]={} k = 0 if charturl then tab[count][k] = charturl k = k + 1 end end local icon = div:match(' 0 then tab[count][k] = div k = k + 1 end end end end end function gethtml(hosturl) local url = hosturl .. '/heizoelpreis-tendenz.htm' local data = getdata(url) if data then local title = data:match("(.-)") local stand = data:match("Stand: (.- %d+:%d+ Uhr)
") local tabdata = data:match("(.-)") make_tab(top,tabdata,"th",0) tabdata = data:match("%c+(.-)") for tr in tabdata:gmatch("(.-)") do make_tab(hop,tr,"td",#hop) end top.title = title:match("(.-),") top.title = top.title .. " " .. stand end end function paintFrame(x, y, w, h, c) local f = 2 -- breite hi= h-(2*f) -- top local _x = x - SCREEN.OFF_X local _y = y - SCREEN.OFF_Y n:PaintBox(_x, _y , w, f, c, conf.corner_large, conf.corner_top) -- bottom n:PaintBox(_x, _y+h-f, w, f, c, conf.corner_large, conf.corner_bottom) -- left n:PaintBox(_x , _y+f, f, hi , c) -- right n:PaintBox(_x+w-f, _y+f, f, hi, c) end function getMaxScreenWidth() local max_w = SCREEN.END_X - SCREEN.OFF_X return max_w end function getMaxScreenHeight() local max_h = SCREEN.END_Y - SCREEN.OFF_Y return max_h end function picView(hosturl,url,titletxt) local fpic = "/tmp/chart.png" local data = getdata(hosturl .. "/" .. url) if data then local urlPic = data:match('