-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock.py
More file actions
executable file
·91 lines (68 loc) · 2.53 KB
/
clock.py
File metadata and controls
executable file
·91 lines (68 loc) · 2.53 KB
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
import os, sys
import csv
import random
import time as clock
from datetime import datetime as dt
from dateutil import parser as dp
os.system('clear')
starttime = clock.time()
def buildTimeList():
time_list = []
# Read the CSV file
try:
with open('/home/nat/Code/LitClockPaPiRus/times.csv', 'r') as f:
reader = csv.reader(f, delimiter='|')
time_list = list(reader)
except IOError:
print("times.csv not found!")
sys.exit(1)
# Convert times into datetime objects
time_list = [[dt.time(dp.parse(x[0])), x[1].rstrip(), x[2].rstrip(), x[3].rstrip(), x[4].rstrip()] for x in time_list]
# Create an empty list to store times by hour
time_list_hourly = [[[] for x in range(60)] for x in range(24)]
# Move the hourly times into the hourly list
for times in time_list:
time_list_hourly[times[0].hour][times[0].minute].append(times)
# Fill in missing times with the next closest time available
for hour in range(24):
for minute in range(60):
if not time_list_hourly[hour][minute]:
time_h = hour
time_m = minute
while True:
time_m = time_m + 1
if time_m > 59:
time_h = time_h + 1
if time_h < 23:
time_h = 0
time_m = 0
if time_list_hourly[time_h][time_m] and isinstance(time_list_hourly[time_h][time_m], list):
time_list_hourly[hour][minute] = (time_h, time_m)
break
# Return the formatted list of times and quotes
return time_list_hourly
def getTimeQuote(timelist, cur_time):
rand = random.SystemRandom()
time_m = cur_time.minute
time_h = cur_time.hour
if isinstance(timelist[time_h][time_m], list):
return random.choice(timelist[time_h][time_m])
else:
time = timelist[time_h][time_m]
return random.choice(timelist[time[0]][time[1]])
# Application Enter
print("Building times list...", end=" ")
time_list = buildTimeList()
print("Done")
# creating a bool value which checks if clock is running
running = True
# keep clock running till running is true
while running:
print("Getting current time...", end=" ")
time = dt.time(dt.now())
quote = getTimeQuote(time_list, time)
print("Done\n")
print(f"{quote[2]}\n")
print(f"{quote[4]}, {quote[3]}")
clock.sleep(60.0 - ((clock.time() - starttime) % 60.0))
os.system("clear")