-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdenuo.py
More file actions
316 lines (295 loc) · 11.4 KB
/
denuo.py
File metadata and controls
316 lines (295 loc) · 11.4 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
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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#coding:utf-8
from Tkinter import *
import Tkinter
import xlrd
from openpyxl import load_workbook
import openpyxl
import itchat
import time
import sys
reload(sys)
sys.setdefaultencoding('utf8')
root = Tk()
root.title('考研打卡')
#root.geometry('420x320') # 设置窗口大小
root.geometry()
root.resizable(width=False, height=True)#禁止拉伸
#完成情况记录表,默认未完成
#flags=[False,False,False]
flags=[]
done_list = []
content_list =[]
def get_item_list_from_excel(item_file):
item_list = []
flags=[]
excelFile = xlrd.open_workbook(item_file)
sheet = excelFile.sheet_by_name('Sheet1')
print(sheet.name, sheet.nrows, sheet.ncols)
row=0
while row<sheet.nrows :
print type(sheet.cell(row, 0).value)
if type(sheet.cell(row, 0).value)==float:#float类型的对象没有encode属性,所以表中纯数字要拎出来处理
item_name = str(sheet.cell(row, 0).value)
else:
item_name = sheet.cell(row, 0).value.encode('utf-8')
if sheet.cell(row, 1).value==1:
item_flag = True
else:
item_flag = False
'''添加表的其他属性
item_start_time= sheet.cell(0, 1).value.encode('utf-8')
'''
#item_list.append((job_num, job_name))
if item_flag==True:
done_list.append(item_name)
item_list.append(item_name)
flags.append(item_flag)
row+=1
print item_list
return item_list,flags
def write_item_list_to_excel(item_file):
wb = load_workbook(item_file)
wb_sheet = wb.get_sheet_by_name('Sheet1')
clear=100
index=0
while index<clear:
index+=1
wb_sheet.cell(index+1, column = 1, value ='')
wb_sheet.cell(index+1, column = 2, value ='')
row=0#这个包里对excel表的行数从1开始
while row<len(content_list):
wb_sheet.cell(row+1, column = 1, value = content_list[row])
wb_sheet.cell(row+1, column = 2, value = flags[row])
row+=1
wb.save(item_file)#保存
return 0
def exit_with_write(root):
write_item_list_to_excel('items.xlsx')
#sendSms(formed_items())
root.quit()
def formed_items():
items="当前时间:\n"+time.ctime()+'\n'
items+="事件列表:\n"
row=0
while row<len(content_list):
if flags[row]:
items+="Done_√ "
else:
items+="Waiting_× "
items+=content_list[row]+'\n'
row+=1
items+="\n 兰大信息院学生项目\n 德诺打卡"
return items
def sendSms(items):
itchat.auto_login(hotReload=True,enableCmdQR=True) #首次扫描登录后后续自动登录
print(itchat.search_friends())
users = itchat.search_friends(name='儿子') # 使用备注名来查找实际用户名
#获取好友全部信息,返回一个列表,列表内是一个字典
print(users)
#获取`UserName`,用于发送消息
if users:
userName = users[0]['UserName']
itchat.send(items,toUserName = userName)
root.title('微信用户:'+itchat.search_friends()['NickName']+' send to'+users[0]['RemarkName'])
else:
root.title('微信用户:'+itchat.search_friends()['NickName']+' send to nobody')
def click_done(item):
loc=content_list.index(item)
flags[loc]=not flags[loc]
if flags[loc]:
done_list.append(content_list[loc])
else:
done_list.remove(content_list[loc])
check()
return 0
def check():
str__='\n'
c=1
for item in done_list:
str__+=str(c)+'_'+str(item)+'\n'
c+=1
lab_done['text']=str__
return 0
def click_del(item):
loc=content_list.index(item)
if flags[loc]:#若已经完成
done_list.remove(item)#从完成列表删除注册信息
del flags[loc]#从状态表删除注册信息
content_list.remove(item)#从事项列表删除注册信息
ck[loc].grid_forget()#删除对应的复选框和按钮
btns_del[loc].grid_forget()
btns_up[loc].grid_forget()
#删除各组件在列表中的注册信息
del ck[loc]
del btns_del[loc]
del btns_up[loc]
return 0
def click_up(item):
loc=content_list.index(item)
if loc==0:#如果是第一个复选框,不能再上移,啥也不做
return 0
#在content_list和flags中上移
content_list[loc],content_list[loc-1]=content_list[loc-1],content_list[loc]
flags[loc],flags[loc-1]=flags[loc-1],flags[loc]
global ck,btns_up,btns_del
#删除事项的复选框、删除键、上移键
for item in ck:
item.grid_forget()
for item in btns_del:
item.grid_forget()
for item in btns_up:
item.grid_forget()
#清空注册表
ck=[]
btns_del=[]
btns_up=[]
#依据两个list更新视图
update_ui()
return 0
def update_ui():
#依据新的事项列表新建复选框、按钮
for item in content_list:
ck.append(btn_build(item))
btn_del,btn_up=btn_del_up_build(item)
btns_del.append(btn_del)
btns_up.append(btn_up)
ck[content_list.index(item)].grid(row=content_list.index(item),sticky=W)
btn_del.grid(row=content_list.index(item),column=2)
btn_up.grid(row=content_list.index(item),column=3)
return 0
def click_add():
#添加输入框和确认键
#调用添加事项函数
global content_input,btn_confirm
root_add=Tkinter.Tk()
root_add.title('新建事项')
root_add.geometry('250x55')
#root_add.resizable(width=False, height=False)#禁止拉伸
content_input=Entry(root_add,text='')
btn_confirm=Button(root_add,text='添加',command=lambda:click_confirm(root_add))
lab=Label(root_add,text='输入新事项:')
lab.pack(anchor=W,side=LEFT)
content_input.pack(side=LEFT)
btn_confirm.pack(side=RIGHT)
Label(root_add,text='~长度最好不要超过12个中文字符(●\'◡\'●)').pack(side=BOTTOM,anchor=W,before=lab)
return 0
def click_confirm(root_add,item='xxx'):
if item =='xxx':
item=content_input.get()#从输入框获取事项
print type(item)
content_list.append(item)#添加到事项列表
flags.append(False)#添加事项状态列表
btn=btn_build(item)#创建按钮
btn_del,btn_up=btn_del_up_build(item)
ck.append(btn)#添加到按钮列表
btns_del.append(btn_del)
btns_up.append(btn_up)
btn.grid(row=content_list.index(item),sticky=W)
btn_del.grid(row=content_list.index(item),column=1)
btn_up.grid(row=content_list.index(item),column=2)
btn_confirm.grid_forget()
content_input.grid_forget()
root_add.destroy()
return 0
#创建按钮对象,为什么用函数?因为在循环中,commander中函数参数总是会指定最后一个item,所以用函数封装一下
def btn_build(item):
btn=Checkbutton(frm, text=item, command=lambda:click_done(item))
if flags[content_list.index(item)]:
btn.select()
return btn
def btn_del_up_build(item):
btn_del=Button(frm,text='del',fg='white',image=del_img,command=lambda:click_del(item))
btn_up=Button(frm,text='up',fg='white',image=up_img,command=lambda:click_up(item))
return btn_del,btn_up
def get_countdown():
from datetime import datetime
#构造一个将来的时间
future = datetime.strptime('2019-12-23 8:30:00','%Y-%m-%d %H:%M:%S')
#当前时间
now = datetime.now()
#求时间差
delta = future - now
hour = delta.seconds/60/60
minute = (delta.seconds - hour*60*60)/60
seconds = delta.seconds - hour*60*60 - minute*60
return str(delta.days)+'天'+ str(hour)+'小时'+str(minute)+'分钟'+ str(seconds)+'秒'
def click_export():
root_exp=Tkinter.Tk()
root_exp.title('确认导出')
root_exp.geometry('300x100')
Label(root_exp,text='建议在当日所有事项都已列举完毕后再导出存档\n您确定要导出吗?\n(1小时内重复导出会覆盖上次导出结果)').pack()
Button(root_exp,text='确认导出',command=lambda:exp_confirm(root_exp)).pack()
return 0
def exp_confirm(root_exp):
with open(time.strftime("%b_%d_%a_%H_%Y",time.localtime())+".txt","w") as f:
f.write("存档时间 :"+time.ctime()+'\n')
f.write("事项列表 :\n")
row=0
while row<len(content_list):
if flags[row]:
f.write("完成_√\t\t\t")
else:
f.write("未成_×\t\t\t")
f.write(content_list[row]+'\n')
row+=1
root_exp.destroy()
if __name__ == '__main__':
#窗体控件
# 标题显示
lab = Label(root, text='今日事项:')
lab.grid(row=0, column=0,sticky=W)
lab_msg = Label(root, text="fininshed:")
lab_msg.grid(row=0, column=1,sticky=W)
frm1=Frame(root,borderwidth=1)
frm1.grid(row=1,column=1)
lab_done=Label(frm1,text='')
lab_done.grid(row=0,column=0,sticky=NW)
# 多选框
frm = Frame(root,borderwidth=1)
frm.grid(row=1,column=0)
#处理图片
del_img = PhotoImage(file = 'del.gif')
up_img = PhotoImage(file = 'up.gif')
#打卡键
ck=[]
btns_del=[]
btns_up=[]
content_list,flags=get_item_list_from_excel('items.xlsx')
for item in content_list:
ck.append(btn_build(item))
btn_del,btn_up=btn_del_up_build(item)
btns_del.append(btn_del)
btns_up.append(btn_up)
ck[content_list.index(item)].grid(row=content_list.index(item),sticky=NW)
btn_del.grid(row=content_list.index(item),column=1,sticky=NW)
btn_up.grid(row=content_list.index(item),column=2,sticky=NW)
check()
btn_add=Button(root,text='新建',command=click_add)
btn_add.grid(row=2,column=0,sticky=E)
btn_wx=Button(root,text='微信提醒',command=lambda:sendSms(formed_items()))
btn_wx.grid(row=2,column=1,sticky=E)
btn_export=Button(root,text='导出今日',command=click_export)
btn_export.grid(row=3,column=1,sticky=E)
btn_exit=Button(root,text='保存退出',command=lambda:exit_with_write(root))
btn_exit.grid(row=4,column=1,sticky=E)
lab_time=Label(root,text='NOW : '+time.strftime("%b %d %a %Y",time.localtime()))
lab_time.grid(row=5,column=0)
lab_contact=Label(root,text='Contact Me : [email protected]')
lab_contact.grid(row=5,column=1,sticky=E)
Label(root,text='考研路漫漫,与君相伴2019~').grid(row=6,column=1)
lab_countdown=Label(root,text='TIME LEFT : '+get_countdown())
lab_countdown.grid(row=6,column=0)
root.mainloop()
#事项长度固定 完成 无意义 因为换行在label内,固定长度以后,ui显示还是对不齐 函数体已经被注释掉
#list写入excel_xlsx文件保存 完成
#加入时间线 完成 因为不是数据库管理,添加时间线有些困难,所以改成了“导出功能”(觉得导入不必要,过去的就过去了)
#读取和写入flags,在excel 完成 done_list不需要保存,done_list在逻辑上可以被content_list和flags确定,功能上只是作为字符串显示而已
#加入倒计时 完成
#加入邮件|公众号提醒
#开机自启
#后台运行
#发送短信提醒
#加入打赏,支付宝花呗二维码
#发送微信提醒 完成
#最小化到右下角托盘
#自定义函数模块化