Exemplo n.º 1
0
def vol_down():
    #print "Vol Down"
    mpcCommand(['mpc', 'volume', '-5'])
    return "nothing"
Exemplo n.º 2
0
def vol_up():
    #print "Vol Up"
    mpcCommand(['mpc', 'volume', '+5'])
    return "nothing"
Exemplo n.º 3
0
def index (name='Payphone Radio'):
        image = 'BBC' # Just to hold the variable
        if request.method == 'POST':
                image = 'now_playing'
                if request.form['submit'] == 'Radio On':
                        mpcCommand(['mpc', 'play', str('1')])
                        image = 'BBC_Radio_1.png'
                elif request.form['submit'] == 'Radio Off':
                        mpcCommand(['mpc', 'play', str('1')])
                        mpcCommand(['mpc', 'close'])
                        mpcCommand(['mpc', 'stop'])
                        mpcCommand(['mpc', 'close'])
                elif request.form['submit'] == 'BBC Radio 1':
                        mpcCommand(['mpc', 'play', str('1')])
                        image = 'BBC_Radio_1.png'
                        return render_template(templateFile, name=name, image = image)
                elif request.form['submit'] == 'BBC Radio 2':
                        mpcCommand(['mpc', 'play', str('2')])
                        image = 'BBC_Radio_2.png'
                        return render_template(templateFile, name=name, image = image)
                elif request.form['submit'] == 'BBC Radio 3':
                        mpcCommand(['mpc', 'play', str('3')])
                        image = 'BBC_Radio_3.png'
                        return render_template(templateFile, name=name, image = image)
                elif request.form['submit'] == 'BBC Radio 4':
                        mpcCommand(['mpc', 'play', str('4')])
                        image = 'BBC_Radio_4.png'
                elif request.form['submit'] == 'BBC Radio 5':
                        mpcCommand(['mpc', 'play', str('13')])
                        image = 'BBC_Radio_5.png'
                        return render_template(templateFile, name=name, image = image)
                elif request.form['submit'] == 'BBC Radio 6':
                        mpcCommand(['mpc', 'play', str('14')])
                        image = 'BBC_Radio_6.png'
                elif request.form['submit'] == 'BBC World Service':
                        mpcCommand(['mpc', 'play', str('5')])
                        image = 'BBC_World_Service.png'
                elif request.form['submit'] == 'BBC Radio 1Extra':
                        mpcCommand(['mpc', 'play', str('6')])
                        image = 'BBC_Radio_1Extra.png'
                elif request.form['submit'] == 'BBC Radio 4Extra':
                        mpcCommand(['mpc', 'play', str('7')])
                        image = 'BBC_Radio_4Extra.png'
                elif request.form['submit'] == 'Classic FM':
                        mpcCommand(['mpc', 'play', str('15')])
                        image = 'Classic_FM.png'
                elif request.form['submit'] == 'WSHU CT NPR':
                        mpcCommand(['mpc', 'play', str('8')])
                        image = 'WSHU.png'
                elif request.form['submit'] == 'WNYC NYC NPR':
                        mpcCommand(['mpc', 'play', str('9')])
                        image = 'WNYC.png'
                elif request.form['submit'] == '97.9 The Bull':
                        mpcCommand(['mpc', 'play', str('16')])
                        image = 'The_Bull.png'
                elif request.form['submit'] == '98Q Danbury':
                        mpcCommand(['mpc', 'play', str('17')])
                        image = '98Q.png'
                elif request.form['submit'] == 'CBC Radio 1':
                        mpcCommand(['mpc', 'play', str('10')])
                        image = 'CBC_Radio_1.png'
                elif request.form['submit'] == 'CBC Radio 2':
                        mpcCommand(['mpc', 'play', str('11')])
                        image = 'CBC_Radio_2.png'
                elif request.form['submit'] == 'CFRC':
                        mpcCommand(['mpc', 'play', str('12')])
                        image = 'CFRC.png'
              
    
        #Volume = mpcCommand(['mpc', 'volume'])
        return render_template(templateFile, name=name, image = image)
Exemplo n.º 4
0
def hello_world(name='Flask Home FM ',css='styles.css'):
    stations = []
    stationURLs = []
    stationOutput = ''

    #read stations data from file
    for x in open('stations2.txt','r'):
        a = x.split("|")
        stations.append(a[0])
        stationURLs.append(a[1].strip())

    #add URL to list
    for stationURL in stationURLs:
        mpcCommand(['mpc', 'add', stationURL])

    #get current position
    position = mpcCommand(['mpc', '-f', '%position%'])
    idx = position.split(b'[')
    position = idx[0].strip()
    if isInteger(position) == False:
        position = 0

    #process post messages from html form
    if request.method == 'POST':
        if request.form['submit'] == 'turn radio on':
            mpcCommand(['mpc', 'play'])
        elif request.form['submit'] == 'turn radio off':
            mpcCommand(['mpc', 'stop'])
        elif request.form['submit'] == 'change':
            mpcCommand(['mpc', 'play', str(request.form['station'])])
        elif request.form['submit'] == 'next station':
            mpcCommand(['mpc', 'next'])
            position  = int(position)+1
            mpcCommand(['mpc', 'play', stations[position]])
        elif request.form['submit'] == 'previous station':
            mpcCommand(['mpc', 'prev'])
            position = int(position) - 1
            mpcCommand(['mpc', 'play', stations[position]])
        elif request.form['submit'] == '+5':
            mpcCommand(['mpc', 'volume', '+5'])
        elif request.form['submit'] == '-5':
            mpcCommand(['mpc', 'volume', '-5'])
        elif request.form['submit'] == 'update playlist':
            mpcCommand(['mpc', 'clear'])

    # update position
    position = mpcCommand(['mpc', '-f', '%position%'])
    idx = position.split(b'[')
    position = idx[0].strip()
    if isInteger(position) == False:
        position = 0

    #update form list to show the selected station
    stationOutput = update_list(stations, position)
    volume = mpcCommand(['mpc', 'volume'])
    return render_template(templateFile, name=name, stations=stationOutput.strip(), volume=volume)
Exemplo n.º 5
0
def hello_world(name='Flask FM'):
	stations = []
	stationURLs = []
	stationOutput = ''
	
	for x in open(txtFile,'r'):
		a = x.split("|")		
		stations.append(a[0])	
		stationURLs.append(a[1].strip())
		
	if request.method == 'POST':
		if request.form['submit'] == 'turn radio on':
			mpcCommand(['mpc', 'play'])
		elif request.form['submit'] == 'turn radio off':
			i2c_write(3)
			#mpcCommand(['mpc', 'stop'])
		elif request.form['submit'] == 'change':
			mpcCommand(['mpc', 'play', str(request.form['station'])])
		elif request.form['submit'] == '+5':
			mpcCommand(['mpc', 'volume', '+5'])
		elif request.form['submit'] == '-5':
			mpcCommand(['mpc', 'volume', '-5'])
		elif request.form['submit'] == 'update playlist':
			mpcCommand(['mpc', 'clear'])
			for stationURL in stationURLs:
				mpcCommand(['mpc', 'add', stationURL])
		elif request.form['submit'] == 'update alarms':
			cron = CronTab(user='******')			
			cron.remove_all(comment='radio alarm ON') #make a nice function	
			cron.remove_all(comment='radio alarm OFF')			

			onValue = str(request.form['turnOn'])
			if len(onValue) == 5 :					
				inputs = onValue.split(':')
				job = cron.new(command='mpc play', comment='radio alarm ON')
				job.hour.on(inputs[0])
				job.minute.on(inputs[1])			
					
				print "new ON at " + inputs[0] + ":" + inputs[1]
			offValue = str(request.form['turnOff'])
			if len(offValue) == 5 :				
				inputs = offValue.split(':')
				job = cron.new(command='mpc stop', comment='radio alarm OFF')
				job.hour.on(inputs[0])
				job.minute.on(inputs[1])								
				print "new OFF at " + inputs[0] + ":" + inputs[1]
			cron.write()
			
		
	position = mpcCommand(['mpc', '-f', '%position%'])
	idx = position.split('[')
	position = idx[0].strip()

	if isInteger(position) == False:
		position = 0

	x = 1
	for station in stations:
		stationOutput += '<option value="' + str(x) + '" '
		if x == int(position):
			stationOutput += 'selected="selected"'
		stationOutput += '>' + station + '</option>'
		x += 1	
		
	status = unicode(mpcCommand(['mpc', 'current']), "utf-8")
	volume = mpcCommand(['mpc', 'volume'])
	localtime = datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S')
	#scheduler.start()
		
	alarmON = ""
	alarmOFF = ""
	alarms = ""
		
	cron = CronTab(user='******')
	for job in cron:
		splitter = str(job.render()).split(' ')
		if splitter[6] == "play":
			alarmON = str(splitter[1]).zfill(2) + ":" + str(splitter[0]).zfill(2)
		if splitter[6] == "stop":
			alarmOFF = str(splitter[1]).zfill(2) + ":" + str(splitter[0]).zfill(2)
		
		alarms += job.render() + '<br/>'
	
	print(alarmON)
	print(alarmOFF)
	
	return render_template(templateFile, name=name, stations=stationOutput.strip(), status=status, volume=volume, localtime=localtime, alarmON=alarmON, alarmOFF=alarmOFF, alarms=alarms)
Exemplo n.º 6
0
from predefines import isInteger, mpcCommand
import subprocess

stations = []
stationURLs = []
stationOutput = ''

for x in open('stations2.txt', 'r'):
    a = x.split("|")
    stations.append(a[0])
    stationURLs.append(a[1].strip())
#print(stations)
#print(stationURLs)

position = 'gjgjqdjqjd[kljllfs'
position = mpcCommand(['mpc', '-f', '%position%'])
print('position', position)

idx = position.split(b'[')
print(idx)

for stationURL in stationURLs:
    mpcCommand(['mpc', 'add', stationURL])
    #mpcCommand(['mpc', 'play'])

position = idx[0].strip()
print(stations[int(position) - 1])

if isInteger(position) == False:
    position = 0
x = 1