Textclock - Displays current time as text - Programming On Unix

Users browsing this thread: 1 Guest(s)
Jayro
Long time nixers
Hey guys,

This is a quick script I put together to display the time in my DWM status bar. Instead of displaying the time like 1:34, it prints out oneTHIRTYfour.

Feel free to use / change it as much as you want. The code could be cleaned up but like I said this was a 5 minute thing. :)

Code:
#! /usr/bin/python

import time

time_conversion = {
        0 : "zero",
        1 : "one",
        2 : "two",
        3 : "three",
        4 : "four",
        5 : "five",
        6 : "six",
        7 : "seven",
        8 : "eight",
        9 : "nine",
        10 : "ten",
        11 : "eleven",
        12 : "twelve",
        13 : "thirteen",
        14 : "fourteen",
        15 : "fifteen",
        16 : "sixteen",
        17 : "seventeen",
        18 : "eighteen",
        19 : "nineteen"
        }


current_hour = time.strftime("%I", time.localtime())
current_minute = time.strftime("%M", time.localtime())

if list(current_hour)[0] == '0':
    current_hour = list(current_hour)[1]

minute_prefix = list(current_minute)[0]
minute_suffix = list(current_minute)[1]

if minute_prefix == "0":
    parsed_minute = "ZERO" + time_conversion[int(minute_suffix)]

elif minute_prefix == "1":
    parsed_minute = time_conversion[int(current_minute)]    

elif minute_prefix == "2":
    parsed_minute = "TWENTY" + time_conversion[int(minute_suffix)]

elif minute_prefix == "3":
    parsed_minute = "THIRTY" + time_conversion[int(minute_suffix)]

elif minute_prefix == "4":
    parsed_minute = "FOURTY" + time_conversion[int(minute_suffix)]

elif minute_prefix == "5":
    parsed_minute = "FIFTY" + time_conversion[int(minute_suffix)]

parsed_hour = time_conversion[int(current_hour)]

print parsed_hour + parsed_minute


Messages In This Thread
Textclock - Displays current time as text - by Jayro - 01-09-2012, 01:57 PM