## Copyright Ambrosini 2017

import re
import random
import time
import datetime
from datetime import datetime

global AX
global ax
AX = 0
AX += 1
ax = str(AX)
#print(" ax = " + ax)


import winsound #as ws


from time import gmtime, strftime ##define strftime as time/date right now
nowTimeDate2=strftime("%Y %a %b %d %H:%M") ##Capture right now Time/date.

print()
print()
print("     " + nowTimeDate2)
print()

global delayTime
global DelayTime

print()
print()
print("     Enter 0 to test the alarm section.")
delayTime = input("     How many hours to next insulin check? (3) ")
if delayTime == "":
    delayTime = 3
DelayTime = int(delayTime)
winsound.MessageBeep(-1)
print()
# =================================================

def Alarm(D):
    AX = 0
    while D >= 1:
       
        d = str(D)
        AX += 1
        ax = str(AX)
        print('     ' + ax, end='...' + "\n")
       
        time.sleep(60)
        D -= 1
        
        import winsound #as wsBeep
        winsound.MessageBeep(1)

def countdown(DelayTime):
    import time
    t = str(DelayTime)
    if t == "1":
       print("     An alarm will start sounding in " + t + " hour...")
    else:
       print("     An alarm will start sounding in " + t + " hours...")
       
    while DelayTime >= 1:
        t = str(DelayTime)
        import datetime
        from datetime import datetime
        from time import gmtime, strftime ##define strftime as time/date right now
        nowTimeDate2=strftime("%Y %a %b %d %H:%M") ##Capture right now Time/date.

        Yz=nowTimeDate2[0:4]  
        mz=nowTimeDate2[9:12]
        dz=nowTimeDate2[13:15]
        Hz=nowTimeDate2[16:18]
        Mz=nowTimeDate2[19:22]

        def month_converter(month): ##convert text month to number
            months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
            return months.index(month) + 1

        mz = month_converter(mz)
        Hz = int(Hz)
        AmPm = " AM"
        if Hz > 12:
            Hz = Hz - 12
            if Hz == 0:
               Hz = 12
            AmPm = " PM"
        if Hz == 0:
            Hz = 12
            AmPm = " AM"
            
        Yz = str(Yz)
        mz = str(mz)
        dz = str(dz)
        Hz = str(Hz)
        Mz = str(Mz)
        
        Tz = ("    " + mz + "-" + dz + "-" + Yz + " " + Hz + ":" + Mz + AmPm)
        print('     ' + t + " " + Tz + "\n")
        time.sleep(3600)
        DelayTime -= 1
        import winsound as wsBeep
        wsBeep.MessageBeep(1)
 
    print('     More Insuin? \n \n \n \n \n')
    Alarm(30000)
    
countdown(DelayTime)


EOB = input("     Strike any key to continue")
