Simulates an old time radio station. Place program files in the numbered folders, station identifications in the ID folder, commercials in the com folder. run from the command line.

directories under the program are: ID, Com, 1,2,3,4,5... ID contains station identifications. COM is commercial recordings. 1,2,3,4,5... each numbered directory contains mp3 files of a particular show.

#!c:\Python25\pythonw.exe
#
from ctypes import *                # Don't change any of these
import os, time, glob, random        # they are all needed
import cgitb; cgitb.enable()        # for operations or problem handling
#
###################################################################
# Robot Radio WHEN V:1.0.0 (C)2012, 2013 Kirk D Bailey All rights reserved. # # Visit our website and jawbone with us on the list! http://www.RobotRadio.info #
###################################################################
#
# 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 # but is taken by the hand to ID or com to play station identifications or commercials respectively.
#
# To add a broadcast group of 'programs', just create a new numbered directory and load the program # files into it- and that's it, the program adapts to it. DO NOT add any directories EXCEPT numbered # broadcast library file directories. The only 2 exceptions are com and ID. com contains commercials. # ID contains station identification blip, anywhere from 5 to 30 seconds long. You can make your own mp3
# files and place them here.
#
winmm = windll.winmm    # a shorthand way to access a function.
#
def mciSend(s): # we access a dlll in the operating system to play mp3 files.
   i=winmm.mciSendStringA(s,0,0,0)
   if i<>0:
      print "Error %d in mciSendString %s" % ( i, s )
#
def playMP3(mp3Name): # and we arap it in code to make using it really easy.
   mciSend("Close All")
   mciSend("Open \"%s\" Type MPEGVideo Alias theMP3" % mp3Name)
   mciSend("Play theMP3 Wait")
   mciSend("Close theMP3")
#
def RandomFile(): # and this lets us pick a ramdom file in the current directory- whatever that is. files=glob.glob("*.mp3") # files is a list of the CURRENT
    file=random.choice(files)                # directories contents
return file # and return the filename to be played
#
os.chdir("./RobotRadio_WHEN/") # starts in cgi-bin, move to application's dirlist=glob.glob("*") # WE WILL NEED THIS LATER IN RandomDir(); once is enough
#
def RandomDir():
    dir=str(1+int(random.random()*(len(dirlist)-2)))
    return dir
#
COUNT=8 # this is how many times to do the loop, then quit. limit=COUNT+1 # this masages a offset to helpo display the loop count print "- - - - - - - - - - - - - - BEGIN Broadcast Day - - - - - - - - - - - - - - - - - -"
#
while COUNT: # this sets the number of loops. Get creative to stop it.
    # ok, let's do the loop.
print "Loop #", limit-COUNT # this lets us display the loop count os.chdir("./ID") # go to the station identification folder
    mp3file=RandomFile()            #
print "Station Identification file:",mp3file," AT: ", time.strftime("%a, %d %b %Y %I:%M %p", time.localtime())
    playMP3(mp3file)                # and pick one at random and play it.
os.chdir("..") # go back to the home directory for this program
    playMP3("./ID/NBCtones.mp3")    # play the top of the hour NBC tones
print "NBCtones.mp3 - play the NBC tri-tone" # we terimmed it off the end of another file, nice and clear and crisp.
    time.sleep(2)                    # a breif pause between file plays
os.chdir("./com") # now back go home, then on to the commercial folder
    mp3file=RandomFile()            # pick a commercial
print "commercial: ",mp3file," AT: ", time.strftime("%a, %d %b %Y %I:%M %p", time.localtime()) # show me the commercial
    playMP3(mp3file)                # and play it.
time.sleep(2) # another pause- so there is a breif hesitation between one and next. os.chdir("..") # this takes us back to the home directory of the application
    newdir=RandomDir()                # pick a dir, any dir,
    os.chdir(newdir)                # and go there.
mp3file=RandomFile() # pick a random file from this directory
    print "Program=", os.getcwd()+"\\"+ mp3file # show us what it is,
print "AT:"+ time.strftime("%a, %d %b %Y %I:%M %p", time.localtime()) # And when,
    playMP3(mp3file)                 # and play it.
os.chdir("../com") # now back go home, then on to the commercial folder
    mp3file=RandomFile()            # pick a commercial
    playMP3(mp3file)                # and play it.
print "commercial: ",mp3file," AT: ", time.strftime("%a, %d %b %Y %I:%M %p", time.localtime()),"<br>" # show me the commercial
    os.chdir("..")                    # go home again.
print "- - - - - - - - - - - - - - - - - - - - - - - - -" # the lines make it easier for they eye to track the half hour segments time.sleep(2) # this gives us some time to do a CNTL-C to break the loop.
    COUNT=COUNT-1
print "DONE. Station shutdown @ ",time.strftime("%a, %d %b %Y %I:%M %p", time.localtime())
#    Now if we could just find a recording of a station shut down...
#    ZZZzzz...




--

-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