Example #1
0
def get_datetime():
    """Get and Build out date time string"""
    local_tz = pytz.timezone('US/Central')
    # set now as current time
    now = datetime.now()
    now = now.replace(tzinfo=pytz.utc).astimezone(local_tz)
    # set and format hour month and period (am/pm)
    hour = datetime.strftime(now, '%-I')
    month = datetime.strftime(now, '%B')
    period = datetime.strftime(now, '%p')

    if period == 'AM':
        period = 'a m'
    else:
        pass

    minute = now.minute
    # uses dates dict in dates file to change int day to ordinal
    day = Dates.get(now.day)

    if minute == 0:
        minute = 'o clock'
    elif minute < 10:
        minute = 'o {}'.format(minute)
    else:
        pass

    # builds time string
    time_str = 'Today is {} {}. The current time is {} {} {}. '.format(
        month, day, hour, minute, period)

    return str(time_str)