Read info from an internet file...
#1
Sad 
hello,

yesterday i started making a script that reads a file on the internet ( http://213.51.131.56/asd2/car.txt ) and outputs this on the screen. the problem is that it doesn't work at all. i have used another script that shows the dutch tv info on the screen (made by nrj_nl).

this is the code that i try to use:

Quote:# nederlandse tv gids
# xbmc python script waarmee de programma's van nu en straks en de films van vandaag
# met detailinformatie te zien zijn.
# bron = http://www.tvgids.nl
# made by [[email protected]][email protected][/email]
# aanpassingen door atmoz

# tvguide_url = 'http://195.95.2.192/playlist2.php'
tvguide_url = 'http://213.51.131.56/asd2/car.txt'

action_previous_menu = 10
action_select_item = 7
action_parent_dir = 9


import urllib, urlparse, poplib, sys, email, string, time, mimetypes, re, os
import xbmcgui, xbmc
import xml.dom.minidom

class tvgids(xbmcgui.window):

               
#opent de url
def openurl(self,url):

filehandle = urllib.urlopen(tvguide_url)
return filehandle


#lees informatie uit bestand
def getlist(self):

dialog = xbmcgui.dialogprogress()
        dialog.create("c-dance tracks","bezig met lezen...")

#lees de pagina
f = self.openurl(tvguide_url)
dataa = f.read()
dialog.close()
#einde def


  #knoppen
  def onaction(self, action):

     if action == action_select_item:

         self.test = xbmcgui.controllabel(300,400,200,200,"","font14","0xffffffff")
         self.addcontrol(self.test)
         self.test.setlabel(dataa)


obj = tvgids()
obj.getlist()
obj.domodal()
del obj

#mydisplay = tvgids()
#mydisplay.getlist()
#mydisplay.domodal()
#del mydisplay

all i want (for now) is to read the file and show the content.

maybe someone can help me with this...

thanks in advance,
atmoz
Reply
#2
i'd recommend, even just for the test, that you change the controllabel to controltextbox (or maybe controltextbox, i can never remember). that way it will hold all the text you give it an auto-wrap. that won't fix your problem at all, but it'll be a little more convenient for testing (i think).

okay, i copied your script over into my script editor and added in the spaces (the forum seems to have flushed everything left), and i think i've figured out what you're trying to do.

it looks like your problem is with the self.test.setlabel(dataa) command. there is no local variable named dataa available for it to use.

you need some other way to make that variable hang around. i recommend making a class variable to contain that information. right after you declare the class, before the openurl def, add this function:
Quote:def init(self):
   self.dataa = ""
(in that example you should put two underscores ("_") before "init" and two underscores after. the forum won't display that, either.)

then, everywhere else that your script refers to "dataa", replace it with "self.dataa". see if that fixes your problem.

if not, you should post the errors that xbmc gives you. you can press the white button on your controller after running a script to get the debug info.

hope that helps!
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#3
thank you for the quick reply and for the help!!

i start the script directly from autoexec.py
if i press the withe button nothing happens...

atmoz

[edit]

okay, now i have figured out how i can run scripts directly from xbmc. this is much much easyer for me to experiment with scripts. every time i change me script i must ftp to the xbox in evox and then go back to xbmc etc..

no i have enabled ftp in bxmc and run the scripts direct in xbmc. :d

the screen "script output" says:

identation error: expected an indented block
file: "q:\scripts\atmoz.py" line 22
def (self):

etc..

(but i don't have a q drive...)

?

atmoz
Reply
#4
the q: drive is just a shortcut to the xbmc home directory. so if you put xbmc in e:/apps/xbmc/ then q: points to e:/apps/xbmc. if you put it somewhere else, q: points there. it's just a shortcut to make paths easier to write so they'll work for everyone.

the indentation error should be easy to fix. find the function that you added (the one i wrote) and delete all the spaces before the def line, and the line in the function. then replace them with tabs or spaces so that they match the way the rest of your script works. does that make sense?

just in case it doesn't: erase the spaces before def init(self): (if there are any) and then add a single tab before it. then move down to the next line, erase any spaces that are there, and then add 2 tabs. that should fix that error.
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#5
thank you it begins to work Smile

with this code i can see the text if i press the white button after the script is loaded:

Quote:# nederlandse tv gids
# xbmc python script waarmee de programma's van nu en straks en de films van vandaag
# met detailinformatie te zien zijn.
# bron = http://www.tvgids.nl
# made by [[email protected]][email protected][/email]
# aanpassingen door atmoz

#tvguide_url = 'http://195.95.2.192:80/playlist2.php'
tvguide_url = 'http://213.51.131.56:80/asd2/car.txt'
#tvguide_url = 'http://192.168.0.24:80/ok.htm'

action_previous_menu = 10
action_select_item = 7
action_parent_dir = 9


import urllib, urlparse, poplib, sys, email, string, time, mimetypes, re, os
import xbmcgui, xbmc
import xml.dom.minidom


class myclass(xbmcgui.window):
def (self):
self.dataa = ""

#def onaction(self, action):
# if action == action_select_item:
# self.straction = xbmcgui.controllabel(300,400,200,200,"","font14","0xffffffff")
# self.addcontrol(straction)
# self.straction.setlabel(self.dataa)


#opent de url
def openurl(self,url):

filehandle = urllib.urlopen(tvguide_url)
return filehandle


#lees informatie uit bestand
def getlist(self):

#dialog = xbmcgui.dialogprogress()
#dialog.create("c-dance tracks","bezig met lezen...")
f = self.openurl(tvguide_url)
self.dataa = f.read()

print (self.dataa)
#dialog.close()


obj = myclass()
obj.getlist()
obj.domodal()
del obj

but with the link that i want to use it goes wrong:
( http://195.95.2.192:80/playlist2.php )

this file refreshes all the time. therefore it is never ready with loading so the script hangs. (this problem do i also have with a selfmade delphi-program on my pc). some people on the internet (delphi forums) have helped me with this and they fixed this with a sort of timer. the program gets 1 second the time for capturing the text in the file and goes than further.

can i made something with python? other files from the internet work fine...

atmoz
Reply
#6
ack. tricky. i tested this out some, and i see what you mean.

i don't know anything about php, so i can't be of much help. if i get some time, maybe i can look into it some more, but i think you're a little beyond my help.
For scripts, script development tools, and documentation, visit my website:
http://www.maskedfox.com/xbmc/
Reply
#7
(alexpoet @ sep. 01 2004,19:00 Wrote:ack. tricky. i tested this out some, and i see what you mean.

i don't know anything about php, so i can't be of much help. if i get some time, maybe i can look into it some more, but i think you're a little beyond my help.
okay. thank you for your good help :bowdown:

this is by the way the code that i use in my delphi program:

Quote:var
stream: tmemorystream;
http: tidhttp;
begin
http := tidhttp.create(self);
try
http.readtimeout := 1000;
stream := tmemorystream.create;
try
try
http.get('http://www.name2serve.com/playlist2.php', stream);
except
// timeout afvangen
end;
stream.position := 0;
memo1.lines.loadfromstream(stream);
finally
stream.free;
end;
finally
http.free;
end;


maybe it helps...?

the problem with xbox/xbmc/python is that not much people work with this.. maybe later (if there are more people interested) it could be fixed.

thanks,
atmoz
Reply

Logout Mark Read Team Forum Stats Members Help
Read info from an internet file...0