[Twisted-Python] help with twisted webserver and rpy script

Jody Gugelhupf knueffle at yahoo.com
Wed May 28 10:52:04 EDT 2008


hi there ppl :)
i have a question, twisted is very new to me, i'm using the twisted webserver to control my
tvcard, i wrote several scripts and got it all working, i also use a rpy script to switch stations
from the website, only that it seems that i need to create for each station a rpy script, i'd
rather have all stations in once rpy file and do it that way, i got it working in php, but is it
possible to write php in rpy? here is an example of one of my rpy scripts to switch stations:

#!/usr/bin/python
import sys
import os
from www.web_types import HTMLResource, FreevoResource

class TestResource(FreevoResource):

    def _render(self, request):
        fv = HTMLResource()
        fv.printHeader(_('LiveTV'), 'styles/main.css',selected=_('Test'))
        form = request.args
        command = "v4lctl setstation MTV"
        os.system(command)
        fv.res += "<html><script language=\"JavaScript\"> close();</script></html>"
        return String( fv.res )
resource = TestResource()



the java stuff is so that when i click on the MTV.rpy link it closes the new window after the
execution of the command, the main site where the MTV.rpy is displayed looks like this:

#!/usr/bin/python
import sys
import os
from www.web_types import HTMLResource, FreevoResource

class TestResource(FreevoResource):

    def _render(self, request):
        fv = HTMLResource()
        fv.printHeader(_('LiveTV'), 'styles/main.css',selected=_('Test'))
        form = request.args
        fv.res += "<html>To start the stream server click <a
href=\"http://10.0.0.1:8085/startstream.rpy\" target=\"_blank\">here.</a> To start the camera
stream server click <a href=\"http://10.0.0.1:8085/startstreamcam.rpy\"
target=\"_blank\">here.</a> To stop the stream-server click<a
href=\"http://195.169.205.24:8085/stopstream.rpy\">here.</a> To switch to the channel you can
simply click on the channel you want to watch. A new window will pop up and close itself
automatically, then the channel should be changed.</html>"
        fv.res += "<html><br><a href=\"MTV.rpy\" target=\"_blank\"> MTV </a> <a href=\"TMF.rpy\"
target=\"_blank\"> TMF </a> <a href=\"national.rpy\" target=\"_blank\"> National Geographic </a>
<a href=\"discovery.rpy\" target=\"_blank\"> Discovery Channel </a> <a href=\"CNN.rpy\"
target=\"_blank\"> CNN </a> <a href=\"BBC1.rpy\" target=\"_blank\"> BBC1 </a> <a href=\"BBC2.rpy\"
target=\"_blank\"> BBC2 </a> <a href=\"net5.rpy\" target=\"_blank\"> Net5 </a> <a
href=\"sbs6.rpy\" target=\"_blank\"> sbs6 </a> <a href=\"veronica.rpy\" target=\"_blank\">
Veronica </a> <a href=\"talpa.rpy\" target=\"_blank\"> talpa </a> <a href=\"rtl4.rpy\"
target=\"_blank\"> rtl4 </a> <a href=\"rtl5.rpy\" target=\"_blank\"> rtl5 </a> <a
href=\"rtl7.rpy\" target=\"_blank\"> rtl7 </a> <a href=\"een.rpy\" target=\"_blank\"> een </a> <a
href=\"euronews.rpy\" target=\"_blank\"> Euronews </a> <a href=\"ard.rpy\" target=\"_blank\"> ARD
</a> <a href=\"zdf.rpy\" target=\"_blank\"> ZDF </a> <a href=\"wdr.rpy\" target=\"_blank\"> WDR
</a> <a href=\"gelderland.rpy\" target=\"_blank\"> TV Gelderland </a> <a href=\"ned1.rpy\"
target=\"_blank\"> Nederland 1 </a> <a href=\"ned2.rpy\" target=\"_blank\"> Nederland 2 </a> <a
href=\"ned3.rpy\" target=\"_blank\"> Nederland 3 </a> <a href=\"ketnet.rpy\" target=\"_blank\">
Ketnet/Canvas </a> <a href=\"lokal.rpy\" target=\"_blank\"> Lokaal Plus </a> <a
href=\"upcinfo.rpy\" target=\"_blank\"> UpcInfo </a> <a href=\"trtint.rpy\" target=\"_blank\">
TRTint </a> <a href=\"rai1.rpy\" target=\"_blank\"> Rai Uno </a> <a href=\"eurosport.rpy\"
target=\"_blank\"> Eurosport </a> <a href=\"nick.rpy\" target=\"_blank\"> Nick/Comedy Central </a>
<a href=\"tellsell.rpy\" target=\"_blank\"> TellSell </a> <a href=\"tv5.rpy\" target=\"_blank\">
TV5 </a> <a href=\"cam.rpy\" target=\"_blank\"> cam </a></br></html>"
        fv.res += "<center><OBJECT ID=\"MediaPlayer\" WIDTH=320 HEIGHT=300
CLASSID=\"CLSID:22D6F312-B0F6-11D0-94AB-0080C74C7E95\" STANDBY=\"Loading Windows Media Player
components...\" TYPE=\"application/x-oleobject\" /><param name=\"autoStart\" value=\"true\"
/><PARAM NAME=\"error\" VALUE=\"item\" /><PARAM NAME=\"stretchToFit\" VALUE=\"false\" /><PARAM
NAME=\"ShowStatusBar\" VALUE=\"true\" /><PARAM NAME=\"FileName\" VALUE=\"mms://10.0.0.1:8083\" />
<EMBED TYPE=\"application/x-mplayer2\" SRC=\"mms://10.0.0.1:8083\"NAME=\"MediaPlayer\" WIDTH=320
HEIGHT=300 ShowStatusBar=\"1\" /></EMBED></OBJECT></center>"
        return String( fv.res )
resource = TestResource()

as you can see and as i said i need to create for each station a rpy file, can i not somehow put
it all in one or make php work in rpy?

thx for any input :)
jody :D


      __________________________________________________________________
Looking for the perfect gift? Give the gift of Flickr! 

http://www.flickr.com/gift/




More information about the Twisted-Python mailing list