Ich habe mir mal überlegt, die Sourcen zu meinem Wetterplugin offen zu legen. Vielleicht hat ja der ein oder andere User da Verbesserungen, die er mit einbringen kann. Auf lange Sicht wäre es natürlich sehr schön, so jemanden auch für unseren Developerkreis zu gewinnen. Kann aber auch nur zum Spaß an der Freud sein!
Es wäre schön, wenn ihr dann auch diesen Thread zur diskussion nutzt und eure Verbesserungen hier gleich postet!
Auf den Verlauf bin ich sehr gespannt
plugin.py
Alles anzeigen
wetter.py
Alles anzeigen
Anbei noch ein tar file mit den Sourcen und dem Hintergrundbild!
Es wäre schön, wenn ihr dann auch diesen Thread zur diskussion nutzt und eure Verbesserungen hier gleich postet!
Auf den Verlauf bin ich sehr gespannt
plugin.py
PHP-Quellcode
- # -*- coding: utf-8 -*-
- ###########################################################################
- #
- # http://newnigma2.to
- #
- # $Id:
- #
- # Copyright (C) 2007,2008 by
- # newnigma2 Team <team@newnigma2.to>
- #
- # 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- #
- ###########################################################################
- from Plugins.Plugin import PluginDescriptor
- from wetter import lookWetter
- def showMain(session, **kwargs):
- session.open(lookWetter, plugin_path)
- def Plugins(path,**kwargs):
- global plugin_path
- plugin_path = path
- return PluginDescriptor(name="E2 Weather Info", description=_("E2 Weather Info"),where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=showMain)
wetter.py
Python-Quellcode
- # -*- coding: utf-8 -*-
- ###########################################################################
- #
- # http://newnigma2.to
- #
- # $Id:
- #
- # Copyright (C) 2007,2008 by
- # newnigma2 Team <team@newnigma2.to>
- #
- # 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., 675 Mass Ave, Cambridge, MA 02139, USA.
- #
- ###########################################################################
- from Screens.Screen import Screen
- from Components.Label import Label
- from Components.Pixmap import Pixmap
- from Components.Button import Button
- from Components.ActionMap import ActionMap
- from Components.AVSwitch import AVSwitch
- from Components.ConfigList import ConfigList, ConfigListScreen
- from Components.config import config, ConfigSubsection, ConfigText, ConfigNumber,getConfigListEntry, ConfigSelection, NoSave
- from enigma import loadPic
- import urllib, re, sys, os
- config.plugins.Weather = ConfigSubsection()
- config.plugins.Weather.plz = ConfigNumber(default = "63864")
- class AppURLopener(urllib.FancyURLopener):
- version = "Mozilla/5.0"
- urllib._urlopener = AppURLopener()
- def loadInfo(CITY):
- try:
- url = "http://www.wetteronline.de/cgi-bin/regframe?3&LANG=de&PLZ=%s&PRG=citybild" % CITY
- data = urllib.urlopen(url).read()
- url = "http://www.wetteronline.de" + re.search("\/cgi-bin[^\"]+", data).group(0)
- url = url.replace("region", "citybild")
- data = urllib.urlopen(url).read()
- data = re.search("<table[^>]+BGCOLOR.+?>(?s).+?<\/table>", data).group(0)
- except:
- print "ERROR load url: %s" % url
- return (myError())
- tag = []
- for day in re.findall("(?i)<b>([a-z]{2}, [0-9]+\.[0-9]+\.)<\/b>", data):
- tag.append(day)
- crad = []
- temps = re.findall("([0-9]+)°C", data)
- for temp in (0, 1, 2):
- crad.append(temps[temp])
- crad.append(temps[temp + 3])
- gif = []
- try:
- for image in re.findall("\/daten\/symbole\/vorhersagen\/standard\/[^\"]+", data)[:9]:
- url = "http://www.wetteronline.de%s" % image
- page = urllib.urlopen(url).readlines()
- blubber = image.split('/')
- datei = "/tmp/%s" %blubber[5]
- gif.append(datei)
- f = open (datei, "w")
- for line in page:
- f.write(line)
- f.close()
- except:
- print "ERROR load images: %s" % url
- return (myError())
- return (tag,crad,gif)
- def myError():
- tag = []
- crad = []
- gif = []
- tag.append("unknow")
- crad.append("unknow")
- gif.append("unknow")
- return (tag,crad,gif)
- class lookWetter(ConfigListScreen,Screen):
- skin = """
- <screen position="150,120" size="420,315" title="newnigma2 Weather Info" >
- <widget name="config" position="10,10" size="400,225" />
- <widget name="key_green" position="240,280" size="140,40" backgroundColor="#21004C00" font="Regular;21" />
- </screen>"""
- def __init__(self, session, plugin_path):
- self.skin_path = plugin_path
- Screen.__init__(self, session)
- self.list = []
- ConfigListScreen.__init__(self, self.list, session = session)
- self.list.append(getConfigListEntry(_("PLZ"), config.plugins.Weather.plz))
- self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
- {
- "ok": self.keyOK,
- "green": self.keyGreen,
- "back": self.close,
- })
- self["key_green"] = Button(_("Start"))
- def KeyOk(self):
- pass
- def keyGreen(self):
- (tag,crad,gif) = loadInfo(str(config.plugins.Weather.plz.value))
- if (tag[0] != "unknow"):
- self.session.open(screenWetter, self.skin_path, tag, crad, gif)
- class screenWetter(Screen):
- skin = """
- <screen position="150,120" size="430,314" title="newnigma2 Weather Info" flags="wfNoBorder" >
- <ePixmap name="mb_bg" position="0,0" zPosition="1" size="441,420" pixmap="~/icons/bg_wetter.png" />
- <widget name="tag0" zPosition="5" position="50,35" size="100,20" font="Regular;14" halign="left" transparent="1" foregroundColor="#000000" />
- <widget name="temp0" zPosition="5" position="45,65" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#2D30DF" />
- <widget name="temp1" zPosition="5" position="45,95" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#F80404" />
- <widget name="pixmap0" position="60,125" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- <widget name="pixmap3" position="60,170" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- <widget name="pixmap6" position="60,215" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- <widget name="tag1" zPosition="5" position="190,35" size="100,20" font="Regular;14" halign="left" transparent="1" foregroundColor="#000000" />
- <widget name="temp2" zPosition="5" position="185,65" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#2D30DF" />
- <widget name="temp3" zPosition="5" position="185,95" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#F80404" />
- <widget name="pixmap1" position="195,125" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- <widget name="pixmap4" position="195,170" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- <widget name="pixmap7" position="195,215" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- <widget name="tag2" zPosition="5" position="322,35" size="100,20" font="Regular;14" halign="left" transparent="1" foregroundColor="#000000" />
- <widget name="temp4" zPosition="5" position="315,65" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#2D30DF" />
- <widget name="temp5" zPosition="5" position="315,95" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#F80404" />
- <widget name="pixmap2" position="327,125" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- <widget name="pixmap5" position="327,170" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- <widget name="pixmap8" position="327,215" zPosition="2" size="50,35" transparent="1" alphatest="on" />
- </screen>"""
- def __init__(self, session, path, tag, crad, gif):
- self.skin_path = path
- self.skin = screenWetter.skin
- Screen.__init__(self, session)
- self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
- {
- "back": self.end,
- })
- for i in range(9):
- name = "pixmap%s" % str(i)
- self[name] = Pixmap()
- for i in range(3):
- name = "tag%s" % str(i)
- self[name] = Label(tag[i])
- for i in range(6):
- name = "temp%s" % str(i)
- self[name] = Label("%s °C" % crad[i])
- self.gif=gif
- self.onShown.append(self.buildGifScreen)
- def buildGifScreen(self):
- i = int(0)
- for x in self.gif:
- try:
- pixmap = loadPic(x,50,35, AVSwitch().getAspectRatioSetting()/2,2, 0,0)
- if pixmap is not None:
- name = "pixmap%s" % str(i)
- self[name].instance.setPixmap(pixmap)
- i += 1
- except:
- print "ERROR loadPNG: %s" % x
- def end(self):
- os.system("rm -rf /tmp/*.gif")
- self.close(False)
Anbei noch ein tar file mit den Sourcen und dem Hintergrundbild!
» time to say goodbye «
Konfuzius sagt:
Erst wenn eine Mücke auf deinen Hoden landet wirst du lernen Probleme ohne Gewalt zu lösen.
Konfuzius sagt:
Erst wenn eine Mücke auf deinen Hoden landet wirst du lernen Probleme ohne Gewalt zu lösen.