1 # -*- coding: utf-8 -*-
4 # www.unwetterzentrale.de und www.uwz.at
9 import xml.sax.saxutils as util
11 from Plugins.Plugin import PluginDescriptor
12 from twisted.web.client import getPage
13 from twisted.internet import reactor
14 from Screens.Screen import Screen
15 from Screens.Console import Console
16 from Components.ActionMap import ActionMap
17 from Components.Label import Label
18 from Components.MenuList import MenuList
19 from Components.AVSwitch import AVSwitch
20 from Components.Pixmap import Pixmap
21 from enigma import eTimer, loadPic
22 from re import sub, search, findall
26 val = AVSwitch().getAspectRatioSetting()
29 ###############################################################################
31 class PictureView(Screen):
33 <screen position="0,0" size="720,576" flags="wfNoBorder" title="UWZ" >
34 <eLabel position="0,0" zPosition="1" size="720,576" backgroundColor="black" />
35 <ePixmap position="635,540" zPosition="2" size="36,20" pixmap="skin_default/buttons/key_info.png" alphatest="on" />
36 <widget name="picture" position="80,10" zPosition="2" size="550,550" />
39 def __init__(self, session):
40 self.skin = PictureView.skin
41 Screen.__init__(self, session)
43 self.aspect = getAspect()
44 self.picfile = "/tmp/uwz.png"
46 self["picture"] = Pixmap()
48 self["actions"] = ActionMap(["OkCancelActions","MovieSelectionActions"],
52 "showEventInfo": self.HelpView,
55 self.getPicTimer = eTimer()
56 self.getPicTimer.callback.append(self.getPic)
57 self.getPicTimer.start(300, True)
60 self.currPic = loadPic(self.picfile, 550, 550, self.aspect, 0, 0, 1)
64 if self.currPic != None:
65 self["picture"].instance.setPixmap(self.currPic)
68 self.session.openWithCallback(self.getPic ,HelpPictureView)
74 class HelpPictureView(Screen):
76 <screen position="25,200" size="670,290" title="Warnstufen" >
77 <eLabel position="0,0" zPosition="1" size="670,290" backgroundColor="black" />
78 <ePixmap position="320,260" zPosition="2" size="36,20" pixmap="skin_default/arrowdown.png" alphatest="on" />
79 <widget name="picture" position="-10,20" zPosition="2" size="690,225" />
82 def __init__(self, session):
83 self.skin = HelpPictureView.skin
84 Screen.__init__(self, session)
86 self["picture"] = Pixmap()
88 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions"],
96 self.aspect = getAspect()
98 self.list.append(pluginpath + "/W_gruen.gif")
99 self.list.append(pluginpath + "/W_gelb.gif")
100 self.list.append(pluginpath + "/W_orange.gif")
101 self.list.append(pluginpath + "/W_rot.gif")
102 self.list.append(pluginpath + "/W_violett.gif")
105 self.onShown.append(self.getPic)
108 self.currPic = loadPic(self.list[self.index], 690, 225, self.aspect, 0, 0, 1)
112 if self.currPic != None:
113 self["picture"].instance.setPixmap(self.currPic)
130 class UnwetterMain(Screen):
133 <screen position="110,83" size="530,430" title="Unwetterzentrale" >
134 <widget name="hmenu" position="5,0" zPosition="1" size="530,220" scrollbarMode="showOnDemand" />
135 <widget name="thumbnail" position="185,250" zPosition="2" size="140,150" />
136 <widget name="thumbland" position="435,390" zPosition="2" size="90,40" />
137 <ePixmap position="20,380" zPosition="2" size="36,20" pixmap="skin_default/buttons/key_menu.png" alphatest="on" />
138 <widget name="statuslabel" position="5,410" zPosition="2" size="530,20" font="Regular;16" halign=\"left\"/>
141 def __init__(self, session):
142 self.loadinginprogress = False
143 self.skin = UnwetterMain.skin
144 self.session = session
145 Screen.__init__(self, session)
147 self["statuslabel"] = Label()
148 self["thumbland"] = Pixmap()
149 self["thumbnail"] = Pixmap()
150 self["hmenu"] = MenuList([])
151 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "MovieSelectionActions"],
155 "right": self.rightDown,
159 "contextMenu": self.switchDeA,
162 self.aspect = getAspect()
163 self.menueintrag = []
165 self.picfile = "/tmp/uwz.png"
166 self.picweatherfile = pluginpath + "/wetterreport.jpg"
167 self.reportfile = "/tmp/uwz.report"
170 f = open(pluginpath + "/last.cfg","r")
176 if self.land == "de":
177 self.baseurl = "http://www.unwetterzentrale.de/uwz/"
178 self.menuurl = self.baseurl + "index.html"
179 self.weatherreporturl = self.baseurl + "lagebericht.html"
181 self.baseurl = "http://www.uwz.at/"
182 self.menuurl = self.baseurl + "index.php"
183 self.weatherreporturl = self.baseurl + "lagebericht.php"
187 # self.onLayoutFinish.append(self.go)
189 self.ThumbTimer = eTimer()
190 self.ThumbTimer.callback.append(self.showThumb)
191 self.ThumbTimer.start(1000, True)
193 def hauptmenu(self,output):
194 self.loadinginprogress = False
195 trans = { 'ß' : 'ß' , 'ä' : 'ä' , 'ö' : 'ö' , 'ü' : 'ü' , 'Ä' : 'Ä', 'Ö' : 'Ö' , 'Ü' : 'Ü'}
196 output= util.unescape(output,trans)
198 if self.land == "de":
199 startpos = output.find('<!-- Anfang Navigation -->')
200 endpos = output.find('<!-- Ende Navigation -->')
201 bereich = output[startpos:endpos]
202 a = findall(r'href=(?P<text>.*?)</a>',bereich)
204 x = x.replace('">',"#").replace('"',"").split('#')
206 link = self.baseurl + x[0]
207 self.menueintrag.append(name)
208 self.link.append(link)
210 startpos = output.find('<div id="mainWindow">')
211 endpos = output.find('<a class="menua" href="http://www.austrowetter.at"')
212 bereich = output[startpos:endpos]
213 a = findall(r'<a class="menub" href=(?P<text>.*?)</a>',bereich)
215 x = x.replace('">',"#").replace('"',"").replace(' style=font-weight:;',"")
219 link = self.baseurl + x[0]
220 self.menueintrag.append(name)
221 self.link.append(link)
223 self["statuslabel"].setText("")
224 self["hmenu"].l.setList(self.menueintrag)
225 self["hmenu"].instance.moveSelectionTo(0)
230 c = self["hmenu"].getCurrent()
232 x = self.menueintrag.index(c)
234 self.session.open(PictureView)
236 self.downloadWeatherReport()
239 c = self["hmenu"].getCurrent()
241 x = self.menueintrag.index(c)
242 # Wetterlagebericht ist Index 0
245 self["statuslabel"].setText("Loading Data")
246 self.downloadPicUrl(url)
247 self.ThumbTimer.start(1500, True)
258 self["hmenu"].pageUp()
262 self["hmenu"].pageDown()
265 def showThumbLand(self):
267 if self.land == "de":
268 picture = pluginpath + "/uwz.png"
270 picture = pluginpath + "/uwzat.png"
271 ptr = loadPic(picture, 90, 40, self.aspect, 0, 0, 1)
273 self["thumbland"].instance.setPixmap(ptr)
277 if self.land == "de":
278 width = 142 ; height = 150
280 width = 142 ; height = 135
281 c = self["hmenu"].getCurrent()
283 x = self.menueintrag.index(c)
285 picture = self.picfile
287 picture = self.picweatherfile
289 ptr = loadPic(picture, width, height, self.aspect, 0, 0, 1)
291 self["statuslabel"].setText("")
292 self["thumbnail"].show()
293 self["thumbnail"].instance.setPixmap(ptr)
295 self["thumbnail"].hide()
297 def getPicUrl(self,output):
298 self.loadinginprogress = False
299 if self.land == "de":
300 startpos = output.find('<!-- Anfang msg_Box Content -->')
301 endpos = output.find('<!-- Ende msg_Box Content -->')
302 bereich = output[startpos:endpos]
303 picurl = search(r'<img src="(?P<text>.*?)" width=',bereich)
304 picurl = self.baseurl + picurl.group(1)
306 picurl = search(r'<img src="showMap(?P<text>.*?)" alt=',output)
307 picurl = self.baseurl + "showMap" + picurl.group(1).replace('&','&')
308 self.downloadPic(picurl)
310 def getPic(self,output):
311 self.loadinginprogress = False
312 f = open(self.picfile, "wb")
316 def getWeatherReport(self,output):
317 self.loadinginprogress = False
318 if self.land == "de":
319 trans = { 'ß' : 'ß' , 'ä' : 'ä' , 'ö' : 'ö' , 'ü' : 'ü' , 'Ä' : 'Ä', 'Ö' : 'Ö' , 'Ü' : 'Ü'}
320 output= util.unescape(output,trans)
321 startpos = output.find('<!-- Anfang msg_Box Content -->')
322 endpos = output.find('<!-- Ende msg_Box Content -->')
323 bereich = output[startpos:endpos]
325 startpos = output.find('<div class="content">')
326 endpos = output.find('<div class="rs_title">Unwettermeldungen</div>')
327 bereich = output[startpos:endpos]
328 u_bereich = bereich.decode("iso-8859-1")
329 bereich = u_bereich.encode("utf-8")
330 bereich = sub('<br />',"\n",bereich)
332 bereich = sub('<[^>]*>',"",bereich)
333 bereich = sub('Fronten- und Isobarenkarte.*',"",bereich)
334 bereich = bereich.strip()
335 bereich = sub("\n\s*\n*", "\n\n", bereich)
337 f = open(self.reportfile, "w")
338 f.write("%s" % bereich)
340 self.session.open(Console,_("Warnlagebericht"),["cat %s" % self.reportfile])
342 def downloadError(self,output):
343 self.loadinginprogress = False
344 self["statuslabel"].setText("Fehler beim Download")
346 def downloadMenu(self):
347 self.loadinginprogress = True
348 getPage(self.menuurl).addCallback(self.hauptmenu).addErrback(self.downloadError)
350 def downloadPicUrl(self,url):
351 self.loadinginprogress = True
352 getPage(url).addCallback(self.getPicUrl).addErrback(self.downloadError)
354 def downloadPic(self,picurl):
355 self.loadinginprogress = True
356 # self["statuslabel"].setText("Lade Bild: %s" % picurl)
357 getPage(picurl).addCallback(self.getPic).addErrback(self.downloadError)
359 def downloadWeatherReport(self):
360 self.loadinginprogress = True
361 # self["statuslabel"].setText("Lade Report: %s" % self.weatherreporturl)
362 getPage(self.weatherreporturl).addCallback(self.getWeatherReport).addErrback(self.downloadError)
365 self.menueintrag = []
367 if self.land == "de":
369 self.baseurl = "http://www.uwz.at/"
370 self.menuurl = self.baseurl + "index.php"
371 self.weatherreporturl = self.baseurl + "lagebericht.php"
374 self.baseurl = "http://www.unwetterzentrale.de/uwz/"
375 self.menuurl = self.baseurl + "index.html"
376 self.weatherreporturl = self.baseurl + "lagebericht.html"
378 f = open(pluginpath + "/last.cfg","w")
382 self.ThumbTimer.start(1500, True)
385 if self.loadinginprogress:
386 reactor.callLater(1,self.exit)
389 unlink(self.reportfile)
393 #############################
395 def main(session, **kwargs):
396 session.open(UnwetterMain)
398 def Plugins(path,**kwargs):
401 return PluginDescriptor(
402 name="Unwetterzentrale",
403 description="www.unwetterzentrale.de und www.uwz.at",
405 where = PluginDescriptor.WHERE_PLUGINMENU,