nixers
Textclock - Displays current time as text - Printable Version
+- nixers (https://nixers.net)
+-- Forum: Development & Graphics (https://nixers.net/Forum-Development-Graphics)
+--- Forum: Programming On Unix (https://nixers.net/Forum-Programming-On-Unix)
+--- Thread: Textclock - Displays current time as text (/Thread-Textclock-Displays-current-time-as-text)


Textclock - Displays current time as text - Jayro - 01-09-2012

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



RE: Textclock - Displays current time as text - Jayro - 01-09-2012

(01-09-2012, 02:19 PM)shix Wrote: Nice script. Why do you prefer text over numbers when displaying time by the way?

I am not sure. Everyone else uses numbers, so why not be different?


RE: Textclock - Displays current time as text - Jayro - 02-09-2012

(02-09-2012, 12:47 AM)NeoTerra Wrote:
(01-09-2012, 02:19 PM)shix Wrote: Nice script. Why do you prefer text over numbers when displaying time by the way?

He's being hipster. OT: Nice script.

You know me, always have to be different. Thanks!


RE: Textclock - Displays current time as text - Shiru - 02-09-2012

Nice, such scripts can always come in handy for things like conky or other programs that display information.


RE: Textclock - Displays current time as text - FreeBSD - 04-09-2012

Haha I have this on my phone and is awesome to put on my computer!!