the robotradio program is coming along. It plays. it dances. it sings. IT selects random libraries and random broadcast files. and it restarts itself with consummate ease. Aka, NOW wtf?!? Jim is exchanging letters with me on this, but does not yet have a solution.

Here's the code of the hour: BEWARE WORD WRAP!!!

#!c:\Python25\pythonw.exe
# Copyright (c) 2011 by James K. Lawless
# ji...@radiks.net http://www.mailsend-online.com
# License: MIT / X11
# See: http://www.mailsend-online.com/license.php
# for full license details.
#
from ctypes import *
import os, os.path, sys, time, glob, random
import cgitb; cgitb.enable()
#
# there are 2 directories under this one- com and id. There are also numbered folders which # contain files of old broadcasts. The system only referrs to number name directories to play programs
#
#
#
#
#
#
#
#
#
print "Content-Type: text/html \n"
print "<html><head><title>Robot Radio WHEN</title></head>"
print '<body bgcolor="white" text="black" links="blue">'
print '<center><h2>Robot Radio WHEN</h2><br>'
#
winmm = windll.winmm
#
def mciSend(s):
   i=winmm.mciSendStringA(s,0,0,0)
   if i<>0:
      print "Error %d in mciSendString %s" % ( i, s )
#
def playMP3(mp3Name):
   mciSend("Close All")
   mciSend("Open \"%s\" Type MPEGVideo Alias theMP3" % mp3Name)
   mciSend("Play theMP3 Wait")
   mciSend("Close theMP3")
#
def RandomFile():
        files=glob.glob("*.mp3")                              # files is a list 
of the CURRENT
        file=random.choice(files)                               # directories 
contents
        print "file=",file,"<br>"
        return file
        
os.chdir("./RobotRadio_WHEN/")                                # starts in 
cgi-bin, move to application's
#                                                                               
        # home directory.

print "- - - - - - - - - - - - - - - - - - - - - - - -<p>"
while 1: # this is an endless loop. Get creative to stop it.
        # ok, let's do the loop.
        os.chdir("./ID")                              # go to the station 
identification folder
        playMP3(RandomFile())                   # and pick one at random and 
play it.
        time.sleep(5)                                   # a breif pause
        os.chdir("../com")                            # now back go home, then 
on to the commercial folder
        playMP3(RandomFile())                   # pick one at random and play 
it.
        time.sleep(5)                                   # another pause
        os.chdir("..")                                        # this takes us 
back to the homne of the application
        #print "cwd=",os.getcwd(),"<br>"      # test code, dummy out later
dirlist=glob.glob("*") # get a listing of the directories in this directory os.chdir(str(1+int(random.random()*len(dirlist)-2))) # randomly select a directory and go to it.
        print "cwd=",os.getcwd()              # test code, dummy out later
        #                                                               # now 
we pick a program library, then
        #                                                               # pick 
a program in it at random and play it.
        #
        mp3file=RandomFile()
        print "program=",mp3file,"<br>"
        # os/chdir("./1") #select a program library randomly and make it 
current.
        print "cwd=",os.getcwd(),"<br>"
# we will log this to the display screen on the console running this program print "cwd=",os.getcwd()," play ",mp3file," AT: ", time.strftime("%a, %d %b %Y %I:%M %p", time.localtime())
        playMP3(mp3file)
        os.chdir("..")                                        # go back to the 
home directory
        print "- - - - - - - - - - - - - - - - - - - - - - - -<p>"
        # Above plays a file named in the variable -mp3file-
time.sleep(5) # this gives us some time to do a CNTL-C to break the loop.
        sys.exit()                                              # maybe.


--

-Shaboom.

    Kirk Bailey
    CEO, Freehold Marketing LLC
    http://www.OneBuckHosting.com/

Fnord!
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to