1 # -*- coding: utf-8 -*-
4 # www.unwetterzentrale.de und www.uwz.at
9 import xml.sax.saxutils as util
10 import urllib, os, sys, string
12 from Plugins.Plugin import PluginDescriptor
13 from twisted.web.client import getPage
14 from twisted.internet import reactor
15 from Screens.Screen import Screen
16 from Screens.Console import Console
17 from Screens.MessageBox import MessageBox
18 from Components.ActionMap import ActionMap
19 from Components.Label import Label
20 from Components.Sources.List import List
21 from Components.MenuList import MenuList
22 from Components.AVSwitch import AVSwitch
23 from Components.Pixmap import Pixmap, MovingPixmap
24 from enigma import eTimer, loadPic, getExif
25 from re import sub, split, search, match, findall
29 val = AVSwitch().getAspectRatioSetting()
32 ###############################################################################
34 class PictureView(Screen):
36 <screen position="0,0" size="720,576" flags="wfNoBorder" title="UWZ" >
37 <eLabel position="0,0" zPosition="1" size="720,576" backgroundColor="black" />
38 <ePixmap position="635,540" zPosition="2" size="36,20" pixmap="skin_default/buttons/key_info.png" alphatest="on" />
39 <widget name="picture" position="80,10" zPosition="2" size="550,550" />
42 def __init__(self, session):
43 self.skin = PictureView.skin
44 Screen.__init__(self, session)
46 self.aspect = getAspect()
47 self.picfile = "/tmp/uwz.png"
49 self["picture"] = Pixmap()
51 self["actions"] = ActionMap(["OkCancelActions","MovieSelectionActions"],
55 "showEventInfo": self.HelpView,
58 self.getPicTimer = eTimer()
59 self.getPicTimer.callback.append(self.getPic)
60 self.getPicTimer.start(300, True)
63 self.currPic = loadPic(self.picfile, 550, 550, self.aspect, 0, 0, 1)
67 if self.currPic != None:
68 self["picture"].instance.setPixmap(self.currPic)
71 self.session.openWithCallback(self.getPic ,HelpPictureView)
77 class HelpPictureView(Screen):
79 <screen position="25,200" size="670,290" title="Warnstufen" >
80 <eLabel position="0,0" zPosition="1" size="670,290" backgroundColor="black" />
81 <ePixmap position="320,260" zPosition="2" size="36,20" pixmap="skin_default/arrowdown.png" alphatest="on" />
82 <widget name="picture" position="-10,20" zPosition="2" size="690,225" />
85 def __init__(self, session):
86 self.skin = HelpPictureView.skin
87 Screen.__init__(self, session)
89 self["picture"] = Pixmap()
91 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions"],
99 self.aspect = getAspect()
101 self.list.append(pluginpath + "/W_gruen.gif")
102 self.list.append(pluginpath + "/W_gelb.gif")
103 self.list.append(pluginpath + "/W_orange.gif")
104 self.list.append(pluginpath + "/W_rot.gif")
105 self.list.append(pluginpath + "/W_violett.gif")
108 self.onShown.append(self.getPic)
111 self.currPic = loadPic(self.list[self.index], 690, 225, self.aspect, 0, 0, 1)
115 if self.currPic != None:
116 self["picture"].instance.setPixmap(self.currPic)
133 class UnwetterMain(Screen):
136 <screen position="110,83" size="530,430" title="Unwetterzentrale" >
137 <widget name="hmenu" position="5,0" zPosition="1" size="530,220" scrollbarMode="showOnDemand" />
138 <widget name="thumbnail" position="185,250" zPosition="2" size="140,150" />
139 <widget name="thumbland" position="435,390" zPosition="2" size="90,40" />
140 <ePixmap position="20,380" zPosition="2" size="36,20" pixmap="skin_default/buttons/key_menu.png" alphatest="on" />
141 <widget name="statuslabel" position="5,410" zPosition="2" size="530,20" font="Regular;16" halign=\"left\"/>
144 def __init__(self, session):
145 self.loadinginprogress = False
146 self.skin = UnwetterMain.skin
147 self.session = session
148 Screen.__init__(self, session)
150 self["statuslabel"] = Label()
151 self["thumbland"] = Pixmap()
152 self["thumbnail"] = Pixmap()
153 self["hmenu"] = MenuList([])
154 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "MovieSelectionActions"],
158 "right": self.rightDown,
162 "contextMenu": self.switchDeA,
165 self.aspect = getAspect()
166 self.menueintrag = []
168 self.picfile = "/tmp/uwz.png"
169 self.picweatherfile = pluginpath + "/wetterreport.jpg"
170 self.reportfile = "/tmp/uwz.report"
173 f = open(pluginpath + "/last.cfg","r")
179 if self.land == "de":
180 self.baseurl = "http://www.unwetterzentrale.de/uwz/"
181 self.menuurl = self.baseurl + "index.html"
182 self.weatherreporturl = self.baseurl + "lagebericht.html"
184 self.baseurl = "http://www.uwz.at/"
185 self.menuurl = self.baseurl + "index.php"
186 self.weatherreporturl = self.baseurl + "lagebericht.php"
190 # self.onLayoutFinish.append(self.go)
192 self.ThumbTimer = eTimer()
193 self.ThumbTimer.callback.append(self.showThumb)
194 self.ThumbTimer.start(1000, True)
196 def hauptmenu(self,output):
197 self.loadinginprogress = False
198 trans = { 'ß' : 'ß' , 'ä' : 'ä' , 'ö' : 'ö' , 'ü' : 'ü' , 'Ä' : 'Ä', 'Ö' : 'Ö' , 'Ü' : 'Ü'}
199 output= util.unescape(output,trans)
201 if self.land == "de":
202 startpos = string.find(output,"<!-- Anfang Navigation -->")
203 endpos = string.find(output,"<!-- Ende Navigation -->")
204 bereich = output[startpos:endpos]
205 a = findall(r'href=(?P<text>.*?)</a>',bereich)
207 x = x.replace('">',"#").replace('"',"")
208 name = x.split("#")[1]
209 link = self.baseurl + x.split("#")[0]
210 self.menueintrag.append(name)
211 self.link.append(link)
213 startpos = string.find(output,'<div id="mainWindow">')
214 endpos = string.find(output,'<a class="menua" href="http://www.austrowetter.at"')
215 bereich = output[startpos:endpos]
216 a = findall(r'<a class="menub" href=(?P<text>.*?)</a>',bereich)
218 x = x.replace('">',"#").replace('"',"").replace(' style=font-weight:;',"")
220 name = x.split("#")[1]
221 link = self.baseurl + x.split("#")[0]
222 self.menueintrag.append(name)
223 self.link.append(link)
225 self["statuslabel"].setText("")
226 self["hmenu"].l.setList(self.menueintrag)
227 self["hmenu"].instance.moveSelectionTo(0)
232 c = self["hmenu"].getCurrent()
234 x = self.menueintrag.index(c)
236 self.session.open(PictureView)
238 self.downloadWeatherReport()
241 c = self["hmenu"].getCurrent()
243 x = self.menueintrag.index(c)
244 # Wetterlagebericht ist Index 0
247 self["statuslabel"].setText("Loading Data")
248 self.downloadPicUrl(url)
249 self.ThumbTimer.start(1500, True)
260 self["hmenu"].pageUp()
264 self["hmenu"].pageDown()
267 def showThumbLand(self):
269 if self.land == "de":
270 picture = pluginpath + "/uwz.png"
272 picture = pluginpath + "/uwzat.png"
273 ptr = loadPic(picture, 90, 40, self.aspect, 0, 0, 1)
275 self["thumbland"].instance.setPixmap(ptr)
279 if self.land == "de":
280 width = 142 ; height = 150
282 width = 142 ; height = 135
283 c = self["hmenu"].getCurrent()
285 x = self.menueintrag.index(c)
287 picture = self.picfile
289 picture = self.picweatherfile
291 ptr = loadPic(picture, width, height, self.aspect, 0, 0, 1)
293 self["statuslabel"].setText("")
294 self["thumbnail"].show()
295 self["thumbnail"].instance.setPixmap(ptr)
297 self["thumbnail"].hide()
299 def getPicUrl(self,output):
300 self.loadinginprogress = False
301 if self.land == "de":
302 startpos = string.find(output,"<!-- Anfang msg_Box Content -->")
303 endpos = string.find(output,"<!-- Ende msg_Box Content -->")
304 bereich = output[startpos:endpos]
305 picurl = search(r'<img src="(?P<text>.*?)" width=',bereich)
306 picurl = self.baseurl + picurl.group(1)
308 picurl = search(r'<img src="showMap(?P<text>.*?)" alt=',output)
309 picurl = self.baseurl + "showMap" + picurl.group(1).replace('&','&')
310 self.downloadPic(picurl)
312 def getPic(self,output):
313 self.loadinginprogress = False
314 f = open(self.picfile, "wb")
318 def getWeatherReport(self,output):
319 self.loadinginprogress = False
320 if self.land == "de":
321 trans = { 'ß' : 'ß' , 'ä' : 'ä' , 'ö' : 'ö' , 'ü' : 'ü' , 'Ä' : 'Ä', 'Ö' : 'Ö' , 'Ü' : 'Ü'}
322 output= util.unescape(output,trans)
323 startpos = string.find(output,'<!-- Anfang msg_Box Content -->')
324 endpos = string.find(output,"<!-- Ende msg_Box Content -->")
325 bereich = output[startpos:endpos]
327 startpos = string.find(output,'<div class="content">')
328 endpos = string.find(output,'<div class="rs_title">Unwettermeldungen</div>')
329 bereich = output[startpos:endpos]
330 u_bereich = bereich.decode("iso-8859-1")
331 bereich = u_bereich.encode("utf-8")
332 bereich = sub('<br />',"\n",bereich)
334 bereich = sub('<[^>]*>',"",bereich)
335 bereich = sub('Fronten- und Isobarenkarte.*',"",bereich)
336 bereich = bereich.strip()
337 bereich = sub("\n\s*\n*", "\n\n", bereich)
339 f = open(self.reportfile, "w")
340 f.write("%s" % bereich)
342 self.session.open(Console,_("Warnlagebericht"),["cat %s" % self.reportfile])
344 def downloadError(self,output):
345 self.loadinginprogress = False
346 self["statuslabel"].setText("Fehler beim Download")
348 def downloadMenu(self):
349 self.loadinginprogress = True
350 getPage(self.menuurl).addCallback(self.hauptmenu).addErrback(self.downloadError)
352 def downloadPicUrl(self,url):
353 self.loadinginprogress = True
354 getPage(url).addCallback(self.getPicUrl).addErrback(self.downloadError)
356 def downloadPic(self,picurl):
357 self.loadinginprogress = True
358 # self["statuslabel"].setText("Lade Bild: %s" % picurl)
359 getPage(picurl).addCallback(self.getPic).addErrback(self.downloadError)
361 def downloadWeatherReport(self):
362 self.loadinginprogress = True
363 # self["statuslabel"].setText("Lade Report: %s" % self.weatherreporturl)
364 getPage(self.weatherreporturl).addCallback(self.getWeatherReport).addErrback(self.downloadError)
367 self.menueintrag = []
369 if self.land == "de":
371 self.baseurl = "http://www.uwz.at/"
372 self.menuurl = self.baseurl + "index.php"
373 self.weatherreporturl = self.baseurl + "lagebericht.php"
376 self.baseurl = "http://www.unwetterzentrale.de/uwz/"
377 self.menuurl = self.baseurl + "index.html"
378 self.weatherreporturl = self.baseurl + "lagebericht.html"
380 f = open(pluginpath + "/last.cfg","w")
384 self.ThumbTimer.start(1500, True)
387 if self.loadinginprogress:
388 reactor.callLater(1,self.exit)
390 os.system("rm %s %s" % (self.picfile, self.reportfile))
394 #############################
396 def main(session, **kwargs):
397 session.open(UnwetterMain)
399 def Plugins(path,**kwargs):
402 return PluginDescriptor(
403 name="Unwetterzentrale",
404 description="www.unwetterzentrale.de und www.uwz.at",
406 where = PluginDescriptor.WHERE_PLUGINMENU,