-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtuntunshu.py
80 lines (67 loc) · 2.36 KB
/
tuntunshu.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
from threading import Timer, Thread
from typing import Any
from modules.taigu import taigu_run, log
from time import sleep, strftime, time, localtime
from pystray import Icon, Menu, MenuItem
from PIL import Image
import os
# from mytool.console import Console
class Tuntunshu:
def __init__(self):
# Console().hide_console()
self.next_time = 0
self.next_t_point = 0
self.task_state = None
self.exit_flag = False
menu = Menu(
MenuItem("log", self.openlog),
MenuItem("Next time", self.show_next_time),
MenuItem("Exit", self.exit),
)
self.icon = Icon("Tuntunshu", icon=Image.open("001.ico"), menu=menu)
self.stray = Thread(target=self.icon.run, name="stray")
self.stray.daemon = True
log.info("Tuntunshu is ready")
def left_click(self):
time_str = strftime("%Y-%m-%d %H:%M:%S", localtime(self.next_t_point))
self.icon.notify("下次蹲点时间", f"{time_str} ")
self.icon.title = f"{time_str}"
pass
def show_next_time(self):
time_str = strftime("%Y-%m-%d %H:%M:%S", localtime(self.next_t_point))
self.icon.notify("下次蹲点时间", f"{time_str} ")
self.icon.title = f"{time_str}"
pass
def openlog(self):
os.system("notepad.exe log.txt")
pass
def exit(self):
self.exit_flag = True
pass
def taigu_timer(self):
self.next_time = taigu_run()
self.task_state = "finished"
self.next_t_point = time() + self.next_time * 60
self.show_next_time()
def time_to_run(self):
if self.next_time is not None:
log.info(f"Creat timer for {self.next_time} minutes")
timer = Timer(self.next_time * 60, self.taigu_timer)
timer.daemon = True
timer.start()
self.task_state = "not_started"
def run(self):
log.info("Tuntunshu is running")
self.stray.start()
while not self.exit_flag:
match self.task_state:
case "finished" | None:
self.time_to_run()
case "not_started":
# log.info("last task is not finished yet")
pass
sleep(1)
if __name__ == "__main__":
tuntunshu = Tuntunshu()
log.info("Tuntunshu is running")
tuntunshu.run()