Podcast alarm


def playPodcast():
	from subprocess import call	
	import os
	from random import randint	
	import datetime	
	podcastDirectory = '/home/fuzzylumpkins/Downloads/Podcasts'	
	podcastList = os.listdir(podcastDirectory)
	podcastList = list(filter(lambda x: '.mp3' in x, podcastList))	
	while datetime.datetime.now().hour <= 8:	
		randomPodcast = randint(0, len(podcastList))		
		toBePlayed = podcastList.pop(randomPodcast)		
		fullPathToPodcast = podcastDirectory + '/' + toBePlayed		
		playedList = podcastDirectory + '/' + 'playedlist.txt'		
		f = open(playedList, 'r')		
		played = f.readlines()		
		f.close()		
		if fullPathToPodcast in played:		
			pass		
		else:			
		    call(['ffplay', '-autoexit', fullPathToPodcast])	
			f = open(playedList, 'a')			
			f.write(fullPathToPodcast)			
			f.write('\n')			
			f.close()	
			os.remove(fullPathToPodcast)
	return None

Send a Comment

Your email address will not be published.