-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.py
More file actions
26 lines (19 loc) · 806 Bytes
/
Copy pathclock.py
File metadata and controls
26 lines (19 loc) · 806 Bytes
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
# clock.py
import time
class Clock:
def get_current_time_digit(self):
"""Get local time by H,M,S format. Example 1,9,2,0,3,0"""
return list(time.strftime("%H%M%S"))
def digit_to_binary_list(self, digit_str):
"""Convert a single string digit to binary 4-digit. Return a list of integer"""
binary_string = format(int(digit_str), "04b")
return [int(bit) for bit in binary_string]
def get_binary_clock_matrix(self):
"""Generate 4X6 matrix"""
digits = self.get_current_time_digit()
columns = [self.digit_to_binary_list(d) for d in digits]
row_matrix = list(zip(*columns))
return row_matrix
if __name__ == "__main__":
clock = Clock()
print(clock.digit_to_binary_list(str(clock.get_current_time_digit())))