From 78343205c9aabc2f838ce32cb3ccb751cfb9ae8b Mon Sep 17 00:00:00 2001 From: Kevin Peterson <kmpeters@anl.gov> Date: Wed, 14 May 2014 16:51:39 -0500 Subject: [PATCH] Use time from xml instead of time.asctime() --- an.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/an.py b/an.py index a8d5d1b..f7aedc2 100755 --- a/an.py +++ b/an.py @@ -7,7 +7,8 @@ import urllib import xml.etree.ElementTree as ET -import time +# for time.asctime() +#!import time # needed for notifyOSX() import os @@ -18,13 +19,11 @@ engineer = "Peterson" # period should match cron job period period = 120 -def notifyConsole(ioc, state): - notify_time = time.asctime() - print "[%s] %s is %s" % (notify_time, ioc, state) +def notifyConsole(ioc, state, time_str): + print "[%s] %s is %s" % (time_str, ioc, state) -def notifyOSX(ioc, state): - notify_time = time.asctime() - notify_command = "%s -title \"%s is %s\" -message \"%s\"" % (osx_command, ioc, state, notify_time) +def notifyOSX(ioc, state, time_str): + notify_command = "%s -title \"%s is %s\" -message \"%s\"" % (osx_command, ioc, state, time_str) os.system(notify_command) # set notification function @@ -47,6 +46,10 @@ f.close() #!print "Parsing XML" root = ET.fromstring(xml_string) +# Get the date and time +time_elem = root.find('time') +time_str = time_elem.text + # Indent for making ET.tostring() output readable def _indent(elem, level=0): ''' @@ -111,4 +114,4 @@ iocs = ioc_list.keys() iocs.sort() for ioc in iocs: - notify(ioc, ioc_list[ioc]) + notify(ioc, ioc_list[ioc], time_str) -- GitLab