aboutsummaryrefslogtreecommitdiff
path: root/challenge-028/paulo-custodio/python/ch-2.py
blob: 3e796f3de52f1d7a22449487a6298c422acf5d13 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/python3

# Challenge 028

# Task #2
# Write a script to display Digital Clock. Feel free to be as creative as you
# can when displaying digits. We expect bare minimum something like "14:10:11".

from datetime import datetime
import time

chars = {
    ' ': ["      ",
          "      ",
          "      ",
          "      ",
          "      "],
    '0': ["  ___ ",
          " |   |",
          " |   |",
          " |   |",
          " |___|"],
    '1': ["      ",
          "     |",
          "     |",
          "     |",
          "     |"],
    '2': ["  ___ ",
          "     |",
          "  ___|",
          " |    ",
          " |___ "],
    '3': ["  ___ ",
          "     |",
          "  ___|",
          "     |",
          "  ___|"],
    '4': ["      ",
          " |   |",
          " |___|",
          "     |",
          "     |"],
    '5': ["  ___ ",
          " |    ",
          " |___ ",
          "     |",
          "  ___|"],
    '6': ["  ___ ",
          " |    ",
          " |___ ",
          " |   |",
          " |___|"],
    '7': ["  ___ ",
          "     |",
          "     |",
          "     |",
          "     |"],
    '8': ["  ___ ",
          " |   |",
          " |___|",
          " |   |",
          " |___|"],
    '9': ["  ___ ",
          " |   |",
          " |___|",
          "     |",
          "     |"],
    ':': ["      ",
          "      ",
          "   .  ",
          "   .  ",
          "      "],
}

CLEAR = "\x1b[H\x1b[2J"
HOME  = "\x1b[H"

def banner(text):
    for row in range(len(chars[' '])):
        for c in text:
            print(chars[c][row], end="")
        print("")

print(CLEAR, end="")
while True:
    now = datetime.now()
    print(HOME, end="")
    banner(now.strftime("%H:%M:%S"))
    time.sleep(0.5)