PDA

View Full Version : [Help] Trying to download a file from web (Python Plugin Enigma2)



LibTiff
14-04-2014, 04:21 PM
Hello guys im trying to download a .txt file from web using this code as a plugin but im getting the download error.
Can any of you spot anything that might cause this?

################################# ################################# #########
from Screens.Screen import Screen
from Screens.MessageBox import MessageBox
from Components.Label import Label
from Components.ActionMap import ActionMap
from Plugins.Plugin import PluginDescriptor
from twisted.web.client import downloadPage
from Tools.Directories import fileExists
################################# ################################# #########
class getFilefromUrl(object):
def __init__(self, session, url=None, path=None):
self.path = path
self.session = session
self.download(url, path)


def download(self, url, path):
downloadPage(url, path).addCallback(self.downloadDo ne).addErrback(self.downloadError )

def downloadError(self, raw):
print "[e2Fetcher.fetchPage]: download Error", raw
self.session.open(MessageBox, text = _("Error downloading: ") + self.path, type = MessageBox.TYPE_ERROR)

def downloadDone(self,raw):
print "[e2Fetcher.fetchPage]: download done", raw


class startscreen(Screen):
skin = """
<screen position="130,150" size="460,150" title="My title" >
<widget name="myText" position="10,20" size="400,50"
valign="center" halign="center" zPosition="2" foregroundColor="white"
font="Regular;22"/>
<widget name="myRedBtn" position="10,110" size="100,40"
backgroundColor="red" valign="center" halign="center" zPosition="2"
foregroundColor="white" font="Regular;20"/>
<widget name="myGreenBtn" position="120,110" size="100,40"
backgroundColor="green" valign="center" halign="center" zPosition="2"
foregroundColor="white" font="Regular;20"/>
</screen>"""
def__init__(self, session, args = 0):
self.session =session
Screen.__init__(self, session)
self["myText"] =Label("Press the Green or OK button to start\n the update.")
self["myRedBtn"] =Label(_("Cancel"))
self["myGreenBtn"] =Label(_("OK"))
self["myActionsMap"] =ActionMap(["SetupActions", "ColorActions"],
{
"ok": self.startPicplayer,
"green": self.startPicplayer,
"red": self.close,
"cancel": self.close,
}, -1)
defupdate(self):
getFilefromUrl(session,"http://www.theaddressthatmytxtfileisuplo aded.com/nameoffile.txt", "/tmp/textfile.txt")
################################# ################################# #########
defmain(session, **kwargs):
session.open(startscreen)
################################# ################################# #########
defPlugins(**kwargs):
returnPluginDescriptor(
name="txtfiledownload",
description="no description for now",
where =PluginDescriptor.WHERE_PLUGINMEN U,
icon="./icon.png",
fnc=main)