各位大佬如何定时提醒,例如:每十分钟提醒一次。
# -*- coding: utf-8 -*-import requests
from lxml import etree
import wx
import time
from plyer import notification
import webbrowser
import wx.adv
req = requests.session()
def get_mid_string(html, start_str, end):
"""
取出中间文本
:param html: 源文本
:param start_str: 前面文本
:param end: 后面文本
:return: 返回第一个符合结果的字符串
"""
try:
start = html.find(start_str)
if start >= 0:
start += len(start_str)
end = html.find(end, start)
if end >= 0:
return html.strip()
except:
return None
class Frame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='', size=(400, 300),name='frame',style=541072448)
self.启动窗口 = wx.Panel(self)
self.Centre()
self.标签1 = wx.StaticText(self.启动窗口,size=(80, 24),pos=(7, 7),label='账号',name='staticText',style=2321)
self.编辑框1 = wx.TextCtrl(self.启动窗口,size=(135, 22),pos=(77, 6),value='',name='text',style=0)
self.标签2 = wx.StaticText(self.启动窗口,size=(51, 24),pos=(21, 35),label='OA密码',name='staticText',style=2321)
self.编辑框2 = wx.TextCtrl(self.启动窗口,size=(133, 22),pos=(78, 34),value='',name='text',style=wx.TE_PROCESS_ENTER|wx.TE_PASSWORD)
self.编辑框2.Bind(wx.EVT_TEXT_ENTER,self.编辑框2_按下Enter键)
self.标签3 = wx.StaticText(self.启动窗口,size=(369, 70),pos=(10, 103),label='密码是OA的密码,如果不知道可以点击\n此处进该网址尝试点击或者联系信息。\n\n请选择提醒间隔',name='staticText',style=2321)
self.标签3.SetForegroundColour('red')
self.标签3.Bind(wx.EVT_LEFT_DOWN,self.标签3_鼠标左键按下)
self.按钮1 = wx.Button(self.启动窗口,size=(80, 32),pos=(237, 2),label='确认',name='button')
self.按钮1.Bind(wx.EVT_BUTTON,self.按钮1_按钮被单击)
self.按钮2 = wx.Button(self.启动窗口,size=(80, 32),pos=(237, 38),label='最小化',name='button')
self.按钮2.Bind(wx.EVT_BUTTON,self.按钮2_按钮被单击)
self.单选框1 = wx.RadioButton(self.启动窗口, size=(59, 24), pos=(78, 230), name='600', label='10分钟',style=wx.RB_GROUP)
self.单选框1.SetValue(True)
self.单选框2 = wx.RadioButton(self.启动窗口, size=(62, 24), pos=(144, 230), name='1800', label='30分钟')
self.单选框3 = wx.RadioButton(self.启动窗口, size=(62, 24), pos=(213, 230), name='3600', label='60分钟')
self.单选框1.Bind(wx.EVT_RADIOBUTTON,self.radioEvent)
self.单选框2.Bind(wx.EVT_RADIOBUTTON,self.radioEvent)
self.单选框3.Bind(wx.EVT_RADIOBUTTON,self.radioEvent)
FolderBookmarkTaskBarIcon()
def 标签3_鼠标左键按下(self, event):
webbrowser.open('http://oa.yuntaiblt.com/login/Login.jsp?logintype=1')
def radioEvent(self, event):
global t
t = event.GetEventObject().Name
def 编辑框2_按下Enter键(self, event):
global tablestring
url = ''
req.get(url)
zh = self.编辑框1.GetValue()
mm = self.编辑框2.GetValue()
data = {}
url1 = ''
req.post(url1, data=data)
url2 = ''
s = req.get(url2)
# print(len(s.text))检测登陆是否成功的源码字数
if len(s.text) >= 80000:
c_dialog = wx.MessageDialog(None, "登陆成功", " ", wx.YES_DEFAULT | wx.ICON_QUESTION)# 创建一个弹窗
if c_dialog.ShowModal() == wx.ID_YES:# 如果点击了提示框的确定按钮
c_dialog.Destroy()# 则关闭提示框
tablestring = get_mid_string(s.text, " __tableStringKey__='", "'")
else:
c_dialog = wx.MessageDialog(None, "账号密码错误", " ", wx.YES_DEFAULT | wx.ICON_QUESTION)# 创建一个弹窗
if c_dialog.ShowModal() == wx.ID_YES:# 如果点击了提示框的确定按钮
c_dialog.Destroy()# 则关闭提示框
self.编辑框2.SetValue("")
def 按钮1_按钮被单击(self, event):
global tablestring
url = ''
req.get(url)
zh = self.编辑框1.GetValue()
mm = self.编辑框2.GetValue()
data = {}
url1 = ''
req.post(url1, data=data)
url2 = ''
s = req.get(url2)
# print(len(s.text))检测登陆是否成功的源码字数
if len(s.text) >= 80000:
c_dialog = wx.MessageDialog(None, "登陆成功", " ", wx.YES_DEFAULT | wx.ICON_QUESTION)# 创建一个弹窗
if c_dialog.ShowModal() == wx.ID_YES:# 如果点击了提示框的确定按钮
c_dialog.Destroy()# 则关闭提示框
tablestring = get_mid_string(s.text, " __tableStringKey__='", "'")
else:
c_dialog = wx.MessageDialog(None, "账号密码错误", " ", wx.YES_DEFAULT | wx.ICON_QUESTION)# 创建一个弹窗
if c_dialog.ShowModal() == wx.ID_YES:# 如果点击了提示框的确定按钮
c_dialog.Destroy()# 则关闭提示框
def 按钮2_按钮被单击(self, event):
self.Hide()
d = 0
while True:
url3 = ''.format(
tablestring)
data2 = {}
w = req.post(url3, data=data2)
html = etree.HTML(w.text)
box1 = html.xpath("//*[@id='_contenttable_62']//font/text()")
box = get_mid_string(w.text, '" requestid="', '">')
notification.notify(title="流程提醒",
message=box1,
timeout=10)
class FolderBookmarkTaskBarIcon(wx.adv.TaskBarIcon):
ICON = 'wx.ico'
TITLE = '测试系统托盘图标'
MENU_ID1, MENU_ID2 = wx.NewIdRef(count=2)
def __init__(self):
super().__init__()
# 设置图标和提示
self.SetIcon(wx.Icon(self.ICON), self.TITLE)
# 绑定菜单项事件
self.Bind(wx.EVT_MENU, self.onOne, id=self.MENU_ID1)
self.Bind(wx.EVT_MENU, self.onExit, id=self.MENU_ID2)
def CreatePopupMenu(self):
'''生成菜单'''
menu = wx.Menu()
# 添加两个菜单项
menu.Append(self.MENU_ID1, '弹个框')
menu.Append(self.MENU_ID2, '退出')
return menu
def onOne(self, event):
wx.MessageBox(box1)
def onExit(self, event):
wx.Exit()
class MyApp(wx.App):
def OnInit(self):
self.frame = Frame()
self.frame.Show(True)
return True
if __name__ == "__main__":
app = MyApp()
app.MainLoop()
该脚本中self.Hide隐藏后我设定notification.notify为提醒,而没有用MessageBox这种形式提醒,为了定时提醒我设定了while true无限循环,time.sleep(600)来达到10分钟进行一次提醒,但是我发现无限循环后就无法执行到while true以后的语句,各位大佬帮忙出个招,顺便问一下self.hide后的frame窗口如何再次显示出来。
页:
[1]