this is a very simple app the helps yous to keep track of time. It says the time very 15 minits, by the way you can change it.

it uses pyttsx which can be dowloaded and install.
copy this code and save it as sayTheTime.pyw and double click it.
it also uses python2.7 you should also note that you have to start it every time the computer
reboots

try it and tell me what you think thanks

import pyttsx
import time

def getMom(_mouth):
    if _mouth == 1:
        return 'january'
    elif _mouth == 2:
        return 'february'
    elif _mouth == 3:
        return 'march'
    elif _mouth == 4:
        return 'april'
    elif _mouth == 5:
        return 'maye'
    elif _mouth == 6:
        return 'june'
    elif _mouth == 7:
        return 'july'
    elif _mouth == 8:
        return 'august'
    elif _mouth == 9:
        return 'september'
    elif _mouth == 10:
        return 'october'
    elif _mouth == 11:
        return 'november'
    elif _mouth == 12:
        return 'december'


def getTheTime(_time):
    hour = _time.tm_hour % 12

    if _time.tm_min == 0 and _time.tm_hour == 0:
        return 'the time is 12 midnite'
    elif _time.tm_min == 0 and _time.tm_hour == 12:
        return 'the time is 12 noon'
    elif _time.tm_hour < 12:
        if _time.tm_min != 0:
            return 'the time is %d: %d am' %(hour, _time.tm_min) 
        else:
            return 'the time is %d oklok am' %(hour)
    elif _time.tm_hour == 12:
        return 'the time is %d: %d pm' %(_time.tm_hour, _time.tm_min)
    elif _time.tm_hour > 12:
        if _time.tm_min != 0:
            return 'the time is %d: %d pm' %(hour, _time.tm_min) 
        else:
            return 'the time is %d oklok pm' %(hour)        


def getDate(day, mouth, year):

    if day == 1:
        return 'the date is %dst %s %d' %(day, getMom(mouth), year)
    elif day == 2:
        return 'the date is %dnd %s %d' %(day, getMom(mouth), year)
    elif day == 3:
        return 'the date is %drd %s %d' %(day, getMom(mouth), year)
    else:
        return 'the date is %dth %s %d' %(day, getMom(mouth), year)


#strat event loop
#it is a forever loop
speek = pyttsx.init()
speek.setProperty('rate', 100)
#get strat time
start_time = time.localtime()
day = start_time.tm_mday
mouth = start_time.tm_mon
year = start_time.tm_year
start_day = 0
while True:

    if start_day != start_time.tm_mday:
        speek.say(getDate(start_time.tm_mday, start_time.tm_mon, start_time.tm_year) + getTheTime(start_time))
        speek.runAndWait()
        start_day = start_time.tm_mday
        time.sleep(880)

    elif strat_time.tm_min % 15 == 0:
        speek.say(getTheTime(start_time))
        speek.runAndWait()
        time.sleep(880)

    strat_time = time.localtime()
Gribouillis commented: thanks for showing pyttsx +13

Recommended Answers

All 3 Replies

there is a bug in the code guys,
when the computer goes to sleep whiles the programe is runing, after you restore it gives you the time that it slept.

Hi guys i have solved the problem and the bug here is the correct code

import pyttsx
import time

#-----------------------------------------
def getMom(_mouth):
    if _mouth == 1:
        return 'january'
    elif _mouth == 2:
        return 'february'
    elif _mouth == 3:
        return 'march'
    elif _mouth == 4:
        return 'april'
    elif _mouth == 5:
        return 'maye'
    elif _mouth == 6:
        return 'june'
    elif _mouth == 7:
        return 'july'
    elif _mouth == 8:
        return 'august'
    elif _mouth == 9:
        return 'september'
    elif _mouth == 10:
        return 'october'
    elif _mouth == 11:
        return 'november'
    elif _mouth == 12:
        return 'december'
#----------------------------------------
#---------------------------------------- 
def getTheTime():
    hour = time.localtime().tm_hour % 12
    if hour == 0:
        hour = 12

    if time.localtime().tm_min == 0 and time.localtime().tm_hour == 0:
        return 'the time is 12 midnite'
    elif time.localtime().tm_min == 0 and time.localtime().tm_hour == 12:
        return 'the time is 12 noon'
    elif time.localtime().tm_hour < 12:
        if time.localtime().tm_min != 0:
            return 'the time is %d: %d am' %(hour, time.localtime().tm_min) 
        else:
            return 'the time is %d oklok am' %(hour)
    elif time.localtime().tm_hour == 12:
        return 'the time is %d: %d pm' %(time.localtime().tm_hour, time.localtime().tm_min)
    elif time.localtime().tm_hour > 12:
        if time.localtime().tm_min != 0:
            return 'the time is %d: %d pm' %(hour, time.localtime().tm_min) 
        else:
            return 'the time is %d oklok pm' %(hour)        
#-------------------------------------------------------------        

def getDate(day, mouth, year):

    if day == 1:
        return 'the date is %dst %s %d' %(day, getMom(mouth), year)
    elif day == 2:
        return 'the date is %dnd %s %d' %(day, getMom(mouth), year)
    elif day == 3:
        return 'the date is %drd %s %d' %(day, getMom(mouth), year)
    else:
        return 'the date is %dth %s %d' %(day, getMom(mouth), year)



# calibiration constant
MINITS = 15

#strat event loop
#it is a forever loop
speek = pyttsx.init()
speek.setProperty('rate', 100)
#get strat time
day = time.localtime().tm_mday
mouth = time.localtime().tm_mon
year = time.localtime().tm_year
start_day = 0

while True:
## this is for start of a new day    
    if start_day != time.localtime().tm_mday:
        speek.say(getDate(time.localtime().tm_mday, time.localtime().tm_mon,
                          time.localtime().tm_year) + getTheTime())
        speek.runAndWait()
        start_day = time.localtime().tm_mday
        time.sleep(((MINITS - (time.localtime().tm_min % MINITS ))* 60))

    elif time.localtime().tm_min % MINITS == 0:
        speek.say(getTheTime())
        speek.runAndWait()
        time.sleep(((MINITS - (time.localtime().tm_min % MINITS ))* 60))

Ok project,some advice or tips.
I would have have used datetime module and not wirte getMom function,because there are many dark spots
when trying to date stuff yourself.

>>> from datetime import date
>>> d = date.today()
>>> d.strftime("%B")
'April'
>>> d.strftime("%A, %d. %B %Y %I:%M%p")
'Sunday, 28. April 2013 12:00AM'

Many elif in getMom function,there are some way to shorten it.
Both list and dictionary is an option here.
Here a example with list and enumerate().

def get_month(m):
    m_lst = ['january', 'february', 'march']
    for index,month in enumerate(m_lst, 1):
        if m == index:
            return month

Test.

>>> get_month(1)
'january'
>>> get_month(3)
'march'
commented: thanks for will post the revised version soon +2
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.