-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask_notify.py
executable file
·116 lines (91 loc) · 3.16 KB
/
task_notify.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
#! /usr/bin/python3
# Copyright(c) 2020 note.jorhelp.cn
# Authored by Jorhelp on: 2020年 01月 21日 星期二 10:48:54 CST
# @desc: 通过notify-send来显示任务
import os
import time, datetime
import Xlib.display
from configparser import ConfigParser
#====================================
# 读取配置文件
#====================================
config=ConfigParser()
user_path=os.path.expanduser("~")
config_path=user_path+"/.config/task/taskrc"
config.read(config_path, encoding='UTF-8')
#====================================
# 全局变量
#====================================
FILE_NAME=config['file']['name']
SWITCH=config['notify']['switch']
INTERVAL=config['notify']['interval']
OLDTIME=datetime.datetime.now()
NEWTIME=datetime.datetime.now()
#====================================
# notify-send
#====================================
def notifySend():
#用os.path.exit()也可以,但如果有一个同名的目录的话就不好办了
if(os.path.isfile(FILE_NAME)):
with open(FILE_NAME) as f:
#文件上次修改时间
file_time= time.localtime(os.stat(FILE_NAME).st_mtime)
tasks=f.readlines()
Ptasks=[]
for i in tasks:
if i.strip()!="" and not i.strip().startswith("//"):
Ptasks.append(i.strip())
msg="\n"
# 没有任务
if len(Ptasks)==0:
os.system("notify-send -t 30000 'Wow! You have finished all the tasks!'")
else:
num=1
for i in Ptasks:
if i[0]=="+":
task=i[1:].strip()
msg+=str(num)+". "+task+'\n'
num+=1
else:
pass
#文件上次修改时间
msg += "\n> "+time.strftime("%Y-%m-%d %H:%M",file_time)
os.system("notify-send -i none -t 30000 'Your tasks' '" + msg +"'")
#没有这个文件
else:
try:
os.system("notify-send -u critical 'no task file @_@'")
except:
pass
#====================================
# 是否全屏
#====================================
def fullScreen():
screen = Xlib.display.Display().screen()
root_win = screen.root
num_of_fs = 0
for window in root_win.query_tree()._data['children']:
window_name = window.get_wm_name()
width = window.get_geometry()._data["width"]
height = window.get_geometry()._data["height"]
if width == screen.width_in_pixels and height == screen.height_in_pixels:
num_of_fs += 1
return num_of_fs
#====================================
# 主函数
#====================================
if __name__ == "__main__":
if SWITCH=="on":
cumd=os.path.expanduser(config['file']['path'])
#切换到主目录
os.chdir(cumd)
while True:
NEWTIME=datetime.datetime.now()
if (NEWTIME-OLDTIME).seconds//60==int(INTERVAL):
# 全屏不显示
if fullScreen()==0:
notifySend()
OLDTIME=NEWTIME
time.sleep(5)
else:
pass