import time

#we pass the script the name of the streetcar and the 3 upcoming times reported

def ttc_alert(streetcar,time1,time2,time3):

    alert = 0
    times = [time1,time2,time3]
    
    #if all 3 upcoming times are less 7 minutes from now, asks if you want VC to automatically check the schedule again in a few minutes

    if time1 < 7 and time2 < 7 and time3 < 7:
        vc.callAction("TTS.Speak","You can't make the next three %s streetcars. Shall I check again in a few minutes?&&5000&&-10"%streetcar, None)
        vc.callAction("OSD.ShowText","%s arrive in: %s, %s, %s minutes&&5000&&-10"%(streetcar,times[0],times[1],times[2]),None) 
        vc.callAction("VC.TellVox","set ttc reminder for %s in %s and %s minutes"%(streetcar,3,10),None)    
            
    #will alert you to upcoming streetcars 7 to 10 mins away, and also ask if you want to set timers for the subsequent car >10 mins away.
    else:    
        for sched in times:    

            if sched == 7:
                vc.callAction("OSD.ShowText","%s arrives in 7 minutes. Leave Now! Leave Now!&&5000&&-10"%streetcar, None)
                vc.callAction("TTS.SpeakSync","%s arrives in 7 minutes. Leave Now! Leave Now!"%streetcar,None) 
                alert = 1
                
            if 7 < sched < 11:
            
                vc.callAction("OSD.ShowText","You can catch the %s in %s minutes.&&5000&&-10"%(streetcar,sched), None)
                vc.callAction("TTS.SpeakSync","You can catch the %s in %s minutes."%(streetcar,sched),None)
                alert = 1             
            
            if sched > 10:
                set_timer1 = sched - 10
                
                set_timer2 = sched - 7
                
                if alert == 1:
                    time.sleep(1)  
                    vc.callAction("TTS.Speak","There's also a %s car leaving in %s minutes. Should I set a reminder?"%(streetcar,sched),None)
                    vc.callAction("VC.TellVox","set ttc reminder for %s in %s and %s minutes"%(streetcar,set_timer1,set_timer2),None)   
                
                else:
                    vc.callAction("TTS.Speak","There's a %s car leaving in %s minutes. Should I set a reminder?"%(streetcar,sched),None)
                    vc.callAction("VC.TellVox","set ttc reminder for %s in %s and %s minutes"%(streetcar,set_timer1,set_timer2),None)             
                break

