码迷,mamicode.com
首页 > 编程语言 > 详细

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

时间:2017-11-04 13:43:21      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:完成   encoding   utf-8   now()   time   输入   sys   tree   编写   

<?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编写某个时刻完成某个任务

标签:完成   encoding   utf-8   now()   time   输入   sys   tree   编写   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!