Public feed #725028

M. Cheeks

public python v1 · immutable
Raw Edit
·published 2007-10-04 01:41 UTC
rendered paste body
#!/usr/bin/env python"""    Author      : mrcheeks    Filename    : neighbors.py    License     : Free to use, modify or distribute    Description : A program to fight against stupid neighbors"""import osimport subprocessimport sysimport randomimport globimport time# the delay to play the next soundtimers = [1900, 2300, 3200, 3600, 2700]# the mp3 foldersoundsdir = "C:\\Projects\\Python\\mp3list\\sounds"programme = "C:\\Tools\\mplayer\\mplayer.exe"class CoughPlayList:    """ Class to play random songs """    def __init__(self):        """ Default constructor """        self.program = programme        self.timers = timers        self.mp3list = glob.glob(soundsdir + os.sep + "*")        def playSong(self):        """ Play a random song """        sound = os.path.join(soundsdir,  random.choice(self.mp3list))        p = subprocess.Popen(args=[self.program , sound], stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=False)        p.wait()def main(argv=None):    """ Script entry point """    # create a new instance of the class    mplayer = CoughPlayList()    # loop forever    while True:        try:            # keyboard interrupt            time.sleep(random.choice(mplayer.timers))            # play a song            mplayer.playSong()        except KeyboardInterrupt:            print("Program interrupted by user")            sys.exit(0)# run the scriptif __name__ == "__main__":    sys.exit(main())