-
Notifications
You must be signed in to change notification settings - Fork 0
/
Zorlan.py
198 lines (159 loc) · 4.8 KB
/
Zorlan.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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
import time
import typer
from typing import List
app = typer.Typer()
# tasks[task_name]=[elapsed_time,current_time,is_paused]
tasks = {}
# WHEN A TASK IS DONE
def say_done(task_name: str):
typer.secho(
f"---------------------------------------------------------------",
fg=typer.colors.BRIGHT_GREEN,
)
typer.secho(
f"task: {task_name} is completed successfully...",
fg=typer.colors.BRIGHT_GREEN,
)
show_elapsed_time(task_name)
# UPDATE THE TIMING OF THE TASK
def update_timing(task_name: str):
if (task_name in tasks) == False:
typer.secho(
f"you were not doing any such task called: {task_name}",
fg=typer.colors.BRIGHT_RED,
)
return
start_time = tasks[task_name][1]
end_time = time.time()
tasks[task_name][0] += end_time - start_time
if tasks[task_name][2] == False:
tasks[task_name][1] = end_time
# SHOW THE ELAPSED TIME OF A TASK
def show_elapsed_time(task_name: str):
if tasks[task_name][2] == False:
update_timing(task_name)
elapsed_time = tasks[task_name][0]
mins, secs = divmod(elapsed_time, 60)
hours, mins = divmod(mins, 60)
typer.secho(
f"elapsed time: {hours} hours {mins} mins {round(secs,3)} secs",
fg=typer.colors.BRIGHT_CYAN,
)
# GENERATE THE NAME OF THE TASK FROM A LIST[STR]
def generate_task_name(task: List[str]):
s = "'"
for word in task:
s += word + " "
return s.strip() + "'"
# INTIALIZE TASK
@app.command()
def init(taskname: List[str]):
# task=typer.prompt("What are you about to do? ")
task_name = generate_task_name(taskname)
tasks[task_name] = [0, time.time(), False]
typer.secho(
f"task: {task_name} has been initialized",
fg=typer.colors.GREEN,
)
# PAUSE
def pause_task(task_name: str):
if (task_name in tasks) == False:
typer.secho(
f"you were not doing any such task: {task_name}", fg=typer.colors.BRIGHT_RED
)
return
if tasks[task_name][2] == True:
typer.secho(
f"task: {task_name} was already paused", fg=typer.colors.BRIGHT_RED)
return
typer.secho(f"task: {task_name} is paused", fg=typer.colors.BRIGHT_GREEN)
tasks[task_name][2] = True
update_timing(task_name)
@app.command()
def pause(taskname: List[str]):
task_name = generate_task_name(taskname)
pause_task(task_name)
@app.command()
def pauseall():
for task in tasks:
pause_task(task)
# RESUME
def resume_task(task_name: str):
if (task_name in tasks) == False:
typer.secho(
f"you were not doing any such task: {task_name}", fg=typer.colors.BRIGHT_RED
)
return
if tasks[task_name][2] == False:
typer.secho(f"task: {task_name} was not paused", fg=typer.colors.RED)
return
tasks[task_name][1] = time.time()
tasks[task_name][2] = False
typer.secho(f"task: {task_name} is resumed", fg=typer.colors.BRIGHT_GREEN)
@app.command()
def resume(taskname: List[str]):
task_name = generate_task_name(taskname)
resume_task(task_name)
@app.command()
def resumeall():
for task in tasks:
resume_task(task)
# CURRENT TASK'S ELAPSED TIME
def show_task(task_name:str):
if task_name in tasks == False:
typer.secho(
f"you were not doing any such task: {task_name}",
fg=typer.colors.BRIGHT_RED,
)
return
typer.secho(
f"---------------------------------------------------------------",
fg=typer.colors.BRIGHT_GREEN,
)
typer.secho(f"task: {task_name}", fg=typer.colors.BRIGHT_GREEN)
show_elapsed_time(task_name)
@app.command()
def show(task:List[str]):
task_name=generate_task_name(task)
show_task(task_name)
@app.command()
def showall():
if len(tasks) == 0:
typer.secho(f"currently no task running", fg=typer.colors.BRIGHT_RED)
for task_name in tasks:
show_task(task_name)
# TASK DONE
@app.command()
def end(taskname: List[str]):
task_name = generate_task_name(taskname)
if task_name in tasks:
say_done(task_name)
del tasks[task_name]
else:
typer.secho(
f"you were not doing any such task: {task_name}",
fg=typer.colors.BRIGHT_RED,
)
@app.command()
def endall():
for task_name in tasks:
say_done(task_name)
tasks.clear()
# EXIT
@app.command()
def exit():
typer.secho("goodbye", fg=typer.colors.BRIGHT_MAGENTA)
raise SystemExit
# MAIN
def main():
typer.secho("hello :)", fg=typer.colors.BRIGHT_MAGENTA)
while True:
command = input().lower()
if command == "exit":
exit()
try:
app(command.split())
except SystemExit:
pass
if __name__ == "__main__":
main()