-
Notifications
You must be signed in to change notification settings - Fork 0
/
tiem.py
164 lines (150 loc) · 4.84 KB
/
tiem.py
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# -*- coding: utf8
import random
import sys
from datetime import datetime
from termcolor import colored
TIMES = {
"en": [
(["preamble"], "It is"),
(["exactly"], "exactly"),
(["about"], "about"),
(["m55", "m05", "m25", "m35"], "five"),
(["m50", "m10"], "ten"),
(["m45", "m15"], "a quarter"),
(["m40", "m20"], "twenty"),
(["m35", "m25"], "twenty-five"),
(["m30"], "half"),
(["m35", "m40", "m45", "m50", "m55"], "to"),
(["m05", "m10", "m15", "m20", "m25", "m30"], "past"),
(["h13", "h01"], "one"),
(["h14", "h02"], "two"),
(["h15", "h03"], "three"),
(["h16", "h04"], "four"),
(["h17", "h05"], "five"),
(["h18", "h06"], "six"),
(["h19", "h07"], "seven"),
(["h20", "h08"], "eight"),
(["h21", "h09"], "nine"),
(["h22", "h10"], "ten"),
(["h23", "h11"], "eleven"),
(["h00", "h12"], "twelve"),
(["m00"], "o' clock"),
(["h12", "h21", "h22", "h23", "h00", "h01", "h02", "h03"], "at"),
(
[
"h13",
"h14",
"h15",
"h16",
"h17",
"h18",
"h19",
"h20",
"h04",
"h05",
"h06",
"h07",
"h08",
"h09",
"h10",
"h11",
],
"in the",
),
(["h21", "h22", "h23", "h00", "h01", "h02", "h03"], "night"),
(["h04", "h05", "h06", "h07", "h08", "h09", "h10", "h11"], "morning"),
(["h12"], "noon"),
(["h13", "h14", "h15", "h16", "h17"], "afternoon"),
(["h18", "h19", "h20"], "evening"),
],
"ch": [
(["preamble"], "Es isch"),
(["exactly"], "genau"),
(["about"], "öppe"),
(["m55", "m05", "m25", "m35"], "füf"),
(["m50", "m10"], "zää"),
(["m45", "m15"], "viertu"),
(["m40", "m20"], "zwänzg"),
(["m40", "m45", "m50", "m55", "m25"], "vor"),
(["m35", "m05", "m10", "m15", "m20"], "ab"),
(["m30", "m25", "m35"], "haubi"),
(["h13", "h01"], "eis"),
(["h14", "h02"], "zwöi"),
(["h15", "h03"], "drüü"),
(["h16", "h04"], "vieri"),
(["h17", "h05"], "füfi"),
(["h18", "h06"], "sächsi"),
(["h19", "h07"], "sibni"),
(["h20", "h08"], "achti"),
(["h21", "h09"], "nüni"),
(["h22", "h10"], "zähni"),
(["h23", "h11"], "eufi"),
(["h00", "h12"], "zwöufi"),
(
[
"h05",
"h06",
"h07",
"h08",
"h09",
"h10",
"h11",
"h12",
"h13",
"h14",
"h15",
"h16",
"h17",
"h18",
"h19",
"h20",
"h21",
"h22",
],
"am",
),
(["h23", "h00", "h01", "h02", "h03", "h04"], "ir"),
(["h21", "h22", "h23", "h00", "h01", "h02", "h03"], "nacht"),
(["h04", "h05", "h06", "h07", "h08", "h09", "h10", "h11"], "morge"),
(["h12"], "mittag"),
(["h13", "h14", "h15", "h16", "h17"], "nami"),
(["h18", "h19", "h20"], "aabe"),
],
}
def showtime():
langs = [lang for lang in TIMES if lang in sys.argv[1:]]
lang = langs[0] if langs else "en"
date = datetime.now()
minutes = round(date.minute / 5) * 5
precision = "exactly" if date.minute == minutes else "about"
str_minutes = f"m{minutes:02}"
fallover_to = 25 if lang == "ch" else 35
hours = (date.hour if minutes < fallover_to else date.hour + 1) % 24
str_hours = f"h{hours:02}"
actives = set([str_hours, str_minutes, "preamble", precision])
on_choices = [
lambda s: colored(s, "yellow", attrs=["bold"]),
lambda s: colored(s, "cyan", attrs=["bold"]),
lambda s: colored(s, "white", attrs=["bold"]),
lambda s: colored(s, "green", attrs=["bold"]),
]
off_color = (
lambda s: "" if "nofill" in sys.argv else colored(s, "blue", attrs=["dark"])
)
newl = "" if "nofill" in sys.argv else "\n"
if "nocolor" in sys.argv:
# only makes sense in 'nofill' mode, but don't care too much
on_choices = [lambda x: x]
written = 0
for activation, string in TIMES[lang]:
is_active = set(activation).intersection(actives)
color = random.choice(on_choices) if is_active else off_color
sys.stdout.write(color(string + " "))
written += len(string)
if written > 25:
sys.stdout.write(newl)
written = 0
sys.stdout.write("\n")
sys.stdout.flush()
if __name__ == "__main__":
showtime()