Verbesserungen am Source vom Wetter-Plugin?

    • Verbesserungen am Source vom Wetter-Plugin?

      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

      PHP-Quellcode

      1. # -*- coding: utf-8 -*-
      2. ###########################################################################
      3. #
      4. # http://newnigma2.to
      5. #
      6. # $Id:
      7. #
      8. # Copyright (C) 2007,2008 by
      9. # newnigma2 Team <team@newnigma2.to>
      10. #
      11. # License: GPL
      12. #
      13. # This program is free software; you can redistribute it and/or modify
      14. # it under the terms of the GNU General Public License as published by
      15. # the Free Software Foundation; either version 2 of the License, or
      16. # (at your option) any later version.
      17. #
      18. # This program is distributed in the hope that it will be useful,
      19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
      20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      21. # GNU General Public License for more details.
      22. #
      23. # You should have received a copy of the GNU General Public License
      24. # along with this program; if not, write to the Free Software
      25. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
      26. #
      27. ###########################################################################
      28. from Plugins.Plugin import PluginDescriptor
      29. from wetter import lookWetter
      30. def showMain(session, **kwargs):
      31. session.open(lookWetter, plugin_path)
      32. def Plugins(path,**kwargs):
      33. global plugin_path
      34. plugin_path = path
      35. return PluginDescriptor(name="E2 Weather Info", description=_("E2 Weather Info"),where = PluginDescriptor.WHERE_EXTENSIONSMENU, fnc=showMain)
      Alles anzeigen


      wetter.py

      Python-Quellcode

      1. # -*- coding: utf-8 -*-
      2. ###########################################################################
      3. #
      4. # http://newnigma2.to
      5. #
      6. # $Id:
      7. #
      8. # Copyright (C) 2007,2008 by
      9. # newnigma2 Team <team@newnigma2.to>
      10. #
      11. # License: GPL
      12. #
      13. # This program is free software; you can redistribute it and/or modify
      14. # it under the terms of the GNU General Public License as published by
      15. # the Free Software Foundation; either version 2 of the License, or
      16. # (at your option) any later version.
      17. #
      18. # This program is distributed in the hope that it will be useful,
      19. # but WITHOUT ANY WARRANTY; without even the implied warranty of
      20. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
      21. # GNU General Public License for more details.
      22. #
      23. # You should have received a copy of the GNU General Public License
      24. # along with this program; if not, write to the Free Software
      25. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
      26. #
      27. ###########################################################################
      28. from Screens.Screen import Screen
      29. from Components.Label import Label
      30. from Components.Pixmap import Pixmap
      31. from Components.Button import Button
      32. from Components.ActionMap import ActionMap
      33. from Components.AVSwitch import AVSwitch
      34. from Components.ConfigList import ConfigList, ConfigListScreen
      35. from Components.config import config, ConfigSubsection, ConfigText, ConfigNumber,getConfigListEntry, ConfigSelection, NoSave
      36. from enigma import loadPic
      37. import urllib, re, sys, os
      38. config.plugins.Weather = ConfigSubsection()
      39. config.plugins.Weather.plz = ConfigNumber(default = "63864")
      40. class AppURLopener(urllib.FancyURLopener):
      41. version = "Mozilla/5.0"
      42. urllib._urlopener = AppURLopener()
      43. def loadInfo(CITY):
      44. try:
      45. url = "http://www.wetteronline.de/cgi-bin/regframe?3&LANG=de&PLZ=%s&PRG=citybild" % CITY
      46. data = urllib.urlopen(url).read()
      47. url = "http://www.wetteronline.de" + re.search("\/cgi-bin[^\"]+", data).group(0)
      48. url = url.replace("region", "citybild")
      49. data = urllib.urlopen(url).read()
      50. data = re.search("<table[^>]+BGCOLOR.+?>(?s).+?<\/table>", data).group(0)
      51. except:
      52. print "ERROR load url: %s" % url
      53. return (myError())
      54. tag = []
      55. for day in re.findall("(?i)<b>([a-z]{2}, [0-9]+\.[0-9]+\.)<\/b>", data):
      56. tag.append(day)
      57. crad = []
      58. temps = re.findall("([0-9]+)&deg;C", data)
      59. for temp in (0, 1, 2):
      60. crad.append(temps[temp])
      61. crad.append(temps[temp + 3])
      62. gif = []
      63. try:
      64. for image in re.findall("\/daten\/symbole\/vorhersagen\/standard\/[^\"]+", data)[:9]:
      65. url = "http://www.wetteronline.de%s" % image
      66. page = urllib.urlopen(url).readlines()
      67. blubber = image.split('/')
      68. datei = "/tmp/%s" %blubber[5]
      69. gif.append(datei)
      70. f = open (datei, "w")
      71. for line in page:
      72. f.write(line)
      73. f.close()
      74. except:
      75. print "ERROR load images: %s" % url
      76. return (myError())
      77. return (tag,crad,gif)
      78. def myError():
      79. tag = []
      80. crad = []
      81. gif = []
      82. tag.append("unknow")
      83. crad.append("unknow")
      84. gif.append("unknow")
      85. return (tag,crad,gif)
      86. class lookWetter(ConfigListScreen,Screen):
      87. skin = """
      88. <screen position="150,120" size="420,315" title="newnigma2 Weather Info" >
      89. <widget name="config" position="10,10" size="400,225" />
      90. <widget name="key_green" position="240,280" size="140,40" backgroundColor="#21004C00" font="Regular;21" />
      91. </screen>"""
      92. def __init__(self, session, plugin_path):
      93. self.skin_path = plugin_path
      94. Screen.__init__(self, session)
      95. self.list = []
      96. ConfigListScreen.__init__(self, self.list, session = session)
      97. self.list.append(getConfigListEntry(_("PLZ"), config.plugins.Weather.plz))
      98. self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
      99. {
      100. "ok": self.keyOK,
      101. "green": self.keyGreen,
      102. "back": self.close,
      103. })
      104. self["key_green"] = Button(_("Start"))
      105. def KeyOk(self):
      106. pass
      107. def keyGreen(self):
      108. (tag,crad,gif) = loadInfo(str(config.plugins.Weather.plz.value))
      109. if (tag[0] != "unknow"):
      110. self.session.open(screenWetter, self.skin_path, tag, crad, gif)
      111. class screenWetter(Screen):
      112. skin = """
      113. <screen position="150,120" size="430,314" title="newnigma2 Weather Info" flags="wfNoBorder" >
      114. <ePixmap name="mb_bg" position="0,0" zPosition="1" size="441,420" pixmap="~/icons/bg_wetter.png" />
      115. <widget name="tag0" zPosition="5" position="50,35" size="100,20" font="Regular;14" halign="left" transparent="1" foregroundColor="#000000" />
      116. <widget name="temp0" zPosition="5" position="45,65" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#2D30DF" />
      117. <widget name="temp1" zPosition="5" position="45,95" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#F80404" />
      118. <widget name="pixmap0" position="60,125" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      119. <widget name="pixmap3" position="60,170" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      120. <widget name="pixmap6" position="60,215" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      121. <widget name="tag1" zPosition="5" position="190,35" size="100,20" font="Regular;14" halign="left" transparent="1" foregroundColor="#000000" />
      122. <widget name="temp2" zPosition="5" position="185,65" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#2D30DF" />
      123. <widget name="temp3" zPosition="5" position="185,95" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#F80404" />
      124. <widget name="pixmap1" position="195,125" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      125. <widget name="pixmap4" position="195,170" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      126. <widget name="pixmap7" position="195,215" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      127. <widget name="tag2" zPosition="5" position="322,35" size="100,20" font="Regular;14" halign="left" transparent="1" foregroundColor="#000000" />
      128. <widget name="temp4" zPosition="5" position="315,65" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#2D30DF" />
      129. <widget name="temp5" zPosition="5" position="315,95" size="80,20" font="Regular;18" halign="center" transparent="1" foregroundColor="#F80404" />
      130. <widget name="pixmap2" position="327,125" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      131. <widget name="pixmap5" position="327,170" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      132. <widget name="pixmap8" position="327,215" zPosition="2" size="50,35" transparent="1" alphatest="on" />
      133. </screen>"""
      134. def __init__(self, session, path, tag, crad, gif):
      135. self.skin_path = path
      136. self.skin = screenWetter.skin
      137. Screen.__init__(self, session)
      138. self["actions"] = ActionMap(["ShortcutActions", "WizardActions"],
      139. {
      140. "back": self.end,
      141. })
      142. for i in range(9):
      143. name = "pixmap%s" % str(i)
      144. self[name] = Pixmap()
      145. for i in range(3):
      146. name = "tag%s" % str(i)
      147. self[name] = Label(tag[i])
      148. for i in range(6):
      149. name = "temp%s" % str(i)
      150. self[name] = Label("%s °C" % crad[i])
      151. self.gif=gif
      152. self.onShown.append(self.buildGifScreen)
      153. def buildGifScreen(self):
      154. i = int(0)
      155. for x in self.gif:
      156. try:
      157. pixmap = loadPic(x,50,35, AVSwitch().getAspectRatioSetting()/2,2, 0,0)
      158. if pixmap is not None:
      159. name = "pixmap%s" % str(i)
      160. self[name].instance.setPixmap(pixmap)
      161. i += 1
      162. except:
      163. print "ERROR loadPNG: %s" % x
      164. def end(self):
      165. os.system("rm -rf /tmp/*.gif")
      166. self.close(False)
      Alles anzeigen



      Anbei noch ein tar file mit den Sourcen und dem Hintergrundbild!
      Dateien
      • wetter.tar

        (71,68 kB, 341 mal heruntergeladen, zuletzt: )
      » time to say goodbye «

      Konfuzius sagt:
      Erst wenn eine Mücke auf deinen Hoden landet wirst du lernen Probleme ohne Gewalt zu lösen.
    • Hatte ja schon im anderen Thread geschrieben ...

      Wäre schön wenn man auch den Stadtnamen nach der PLZ Eingabe sehen/eingegen koennte so wie auf der wetteronline site...bzw kann man nicht auch nach Stadtnamen suchen lassen ? Bei wetteronline geht da auch ...

      in def loadInfo .. kann man da nicht noc die suche nach namen reinnehmen...

      die ausgabe bei denen sieht so aus z.b. fuer Amsterdam

      wetteronline.de/Niederlande/Amsterdam.htm

      oder Rennes in Frankreich

      wetteronline.de/Frankreich/Rennes.htm

      Wenn ich z.b nach Frankfurt Suche bekomme ich

      wetteronline.de/Hessen/Frankfurt.htm
      Why drink & Drive ?

      When you can smoke & fly 8)

      Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von dreamedge ()

    • ich bin die nächsten paar tage nicht da aber du kannst das gerne erweitern 8) 8)
      » time to say goodbye «

      Konfuzius sagt:
      Erst wenn eine Mücke auf deinen Hoden landet wirst du lernen Probleme ohne Gewalt zu lösen.
    • hmmm jo kann config.plugins.Weather.plz = ConfigNumber(default = "63864") nicht :D
      » time to say goodbye «

      Konfuzius sagt:
      Erst wenn eine Mücke auf deinen Hoden landet wirst du lernen Probleme ohne Gewalt zu lösen.