#!/usr/bin/env python
# coding=utf-8
# KUOW.py
# with help from János Juhász on Tutor list
# see http://thread.gmane.org/gmane.comp.python.tutor/46607
"""
Start KUOW streaming audio on my computer starting at a time I set
"""
import time
import os
print \
"""
Enter starting time as hh:mm or h:mm. However, if want to start
listening/recording on the hour, you may enter just that hour in 1 or 2 digits.
E.g. 4:00 as 4 or 04, 22:00 as 22
The program allows 30 seconds to start bringing in a KUOW program, so the
starting time entered is actually converted to a time 30 seconds earlier.
E.g. 04:00 becomes 3:59:30, and 22:30 becomes 22:29:30
"""
timeStart = raw_input("Enter starting time: ")
#cases such as "4" or "4:30" -- puts a "0" in front of entered hour
if len(timeStart) == 1 or len(timeStart) == 4:
timeStart = "0" + timeStart
#cases such as 02, or 10
if len(timeStart) == 2:
if timeStart == "00":
timeStart = "23"
else:
timeStart = int(timeStart) - 1
timeStart = str(timeStart) + ":59:30"
#cases such as 03:00, 13:30
elif len(timeStart) == 5:
hour = timeStart[:2]
min = timeStart[3:5]
if min == "00":
min = "60"
hour = str(int(hour) - 1)
min = str(int(min) -1)
if len(min) == 1:
min = "0" + min
timeStart = hour + ":" + min + ":30"
print "starting time set as", timeStart
b = timeStart
(bhour, bmin, bsec) = b.split(':')
bsec = int(bsec) + int(bmin)*60 + int(bhour)*3600
act = time.localtime()
actsec = act.tm_sec + act.tm_min*60 + act.tm_hour*3600
wait = bsec - actsec
if wait < 0: # startTime is in next day
wait += 3600*24
print "wait is", wait
time.sleep(wait)
print 'Starting now'
print "Starting now, at", time.strftime('%H:%M:%S')
os.startfile('http://www.kuow.org/real.ram')