首页 > 编程语言 > 详细

Python编写某个时刻完成某个任务

时间:2017-11-04 12:56:24      阅读:345      评论:0      收藏:0      [点我收藏+]
<?xml version="1.0"?>
<data>
<work name="work1">
<message>上课</message>
<showtime>2017-11-04 11:38:20</showtime>
</work>
<work name="work2">
<message>参加XXX会议</message>
<showtime>2017-11-04 11:38:22</showtime>
</work>
<work name="work3">
<message>参加XXX聚会</message>
<showtime>2017-11-04 11:38:25</showtime>
</work>
</data>



# _*_ encoding:utf-8 _*_
__data__ = ‘ 8:58‘

import os,sys
from datetime import datetime
import xml.etree.cElementTree as ET


class ClockMsg():

def ShowMsg(self, message):
print (message)

def WaitTime(self, message, showtime):
strnext_time = datetime.strptime(showtime, "%Y-%m-%d %H:%M:%S") #提醒时间
while True:
str_now = datetime.now() #获取当前时间
str_now_time = str_now.strftime(‘%Y-%m-%d %H:%M:%S‘)

       if str(str_now_time) > str(strnext_time):
          self.ShowMsg("输入时间不能早于当前时间")
            return
            if str(str_now_time) == str(strnext_time):
self.ShowMsg(message)
return

def GetMsg(self):
tree = ET.parse("message.xml") #打开xml文档
root = tree.getroot() #获得root节点
for work in root.findall(‘work‘): #找到root节点下的所有work节点
message = work.find(‘message‘).text #子节点下节点message的值
showtime = work.find(‘showtime‘).text #子节点下节点showtime的值
self.WaitTime(message, showtime)

if __name__ == "__main__":
clockmsg = ClockMsg()
clockmsg.GetMsg()

Python编写某个时刻完成某个任务

原文:http://www.cnblogs.com/onlyhold/p/7782912.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!