vielen Dank den Profis hier (das erst mal vorweg)
das Problem mit der config war ganz einfach, das ich die URL in Anführungszeichen drin hatte, ohne funktioniert es hervorragend
mein erstes Produkt in Python funktioniert erstmal (ist natürlich sehr verbesserungswürdig, insbesondere die Verwendung von html5lib und ElementTree, da muss ich erst mal begreifen wie das tut und vor allem wie ich es per ipkg installieren lassen kann)
und hier mein Projekt, ein Plugin für die Dreambox unter Enigma2:
Code: Alles auswählen
# -*- coding: utf-8 -*-
#
# Heizoelpreise
# http://www.esyoil.com/
#
# 0.02
#
#
# Enigma2 Plugin
#
# Author: fs-cl
#
import os, sys
from Plugins.Plugin import PluginDescriptor
from twisted.web.client import getPage
from twisted.internet import reactor
from Screens.Screen import Screen
from Screens.Console import Console
from Components.ActionMap import ActionMap
from Components.Label import Label
from Components.ScrollLabel import ScrollLabel
from Components.Sources.List import List
from enigma import eTimer
from re import sub, split, search, match, findall
from string import find, atoi, strip
import urllib
class HeizoelMain(Screen):
skin = """
<screen position="110,83" size="980,390" title="%s" >
<widget name="details1" position="5,2" size="980,60" font="Regular;30" halign="left" />
<eLabel position="0,390" size="980,3" backgroundColor="white" />
<widget name="details" position="5,55" size="980,330" font="Regular;30" halign="left" />
<widget name="statuslabel" position="5,390" size="980,0" font="Regular;12" halign="left"/>
</screen>""" % "Heizoel V0.1a"
def ok(self):
self.exit()
def __init__(self, session):
self.loadinginprogress = False
self.session = session
self.skin = HeizoelMain.skin
Screen.__init__(self, session)
self["details1"] = ScrollLabel("")
self["details"] = ScrollLabel("")
self["statuslabel"] = Label("")
self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ChannelSelectBaseActions"],
{
"ok": self.exit,
"cancel": self.exit,
}, -1)
self.configfile = pluginpath + "/heizoel.cfg"
try:
f = open(self.configfile,"r")
line2 = f.readline()
except:
line2 ="http://www.esyoil.com/heiz%C3%B6lpreise/heiz%C3%B6l_Stuttgart_e2.php"
#seite = urllib.urlopen("http://www.esyoil.com/heiz%C3%B6lpreise/heiz%C3%B6l_Obermarchtal_e3.php")
seite = urllib.urlopen(line2)
seite2 = seite.read()
seite.close()
x = findall('\d{2}\,\d{2}',seite2)
diff2000 = str ('%+.2f' %((float(x[1].replace(',','.')))-(float(x[0].replace(',','.')))))
diff2500 = str ('%+.2f' %((float(x[3].replace(',','.')))-(float(x[2].replace(',','.')))))
diff3000 = str ('%+.2f' %((float(x[5].replace(',','.')))-(float(x[4].replace(',','.')))))
diff3500 = str ('%+.2f' %((float(x[7].replace(',','.')))-(float(x[6].replace(',','.')))))
diff4000 = str ('%+.2f' %((float(x[9].replace(',','.')))-(float(x[8].replace(',','.')))))
sum2000 = str ('%4.2f' %(float(x[1].replace(',','.'))*20))
sum2500 = str ('%4.2f' %(float(x[3].replace(',','.'))*25))
sum3000 = str ('%4.2f' %(float(x[5].replace(',','.'))*30))
sum3500 = str ('%4.2f' %(float(x[7].replace(',','.'))*35))
sum4000 = str ('%4.2f' %(float(x[9].replace(',','.'))*40))
z0 = "Menge: Gesamtpreis\tEuro/100L (gestern / Diff.)"
z20= "2000 Liter: " + sum2000 + "\t" + x[1] + " ( " + x[0] + " / " + diff2000 + " )\n\n"
z25= "2500 Liter: " + sum2500 + "\t" + x[3] + " ( " + x[2] + " / " + diff2500 + " )\n\n"
z30= "3000 Liter: " + sum3000 + "\t" + x[5] + " ( " + x[4] + " / " + diff3000 + " )\n\n"
z35= "3500 Liter: " + sum3500 + "\t" + x[7] + " ( " + x[6] + " / " + diff3500 + " )\n\n"
z40= "4000 Liter: " + sum4000 + "\t" + x[9] + " ( " + x[8] + " / " + diff4000 + " )\n"
menux = z0
bereich= z20 + z25 + z30 + z35 + z40
self["details"].setText(bereich)
self["details1"].setText(z0)
#self["statuslabel"].setText(line2)
def exit(self):
self.close()
#############################
def main(session, **kwargs):
session.open(HeizoelMain)
def Plugins(path,**kwargs):
global pluginpath
pluginpath = path
return PluginDescriptor(
name="Heizoelpreise",
description="Heizoelpreise",
icon="heizoel.png",
where = PluginDescriptor.WHERE_PLUGINMENU,
fnc=main)
die URL ist in der heizoel.cfg abgelegt und kann somit abgeändert werden