-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
69 lines (60 loc) · 2.76 KB
/
main.py
File metadata and controls
69 lines (60 loc) · 2.76 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
from read_json import *
parser = argparse.ArgumentParser()
parser.add_argument('-i','--initialize', action='store_const', dest='mode_val',const='initialize', help='initialize an rss feed')
parser.add_argument('-a','--add', action='store_const', dest='mode_val', const='add', help='add an rss item')
parser.add_argument('-f','--filename', action='store', help='file name e.g. rss.xml')
parser.add_argument('-j','--jsonfilename', action='store', help='file name e.g. rss.xml')
args = parser.parse_args()
if args.mode_val:
MODE=args.mode_val
else:
print "Syntax ERROR, please choose a mode."
exit()
if args.filename and args.jsonfilename:
filename=args.filename
jsonfilename=args.jsonfilename
else:
print "Please put the filename on the command line."
exit()
#jsonfilename= 'convert_this_to_XML.json'
jsonfilename=args.jsonfilename
jsonfile = open(jsonfilename,'r')
# validate/parse a json file
data = json_data(jsonfile)
jsonfile.close()
if data is False:
print 'The input file is not a proper json configuration. Check the input file.'
exit()
# data looks like [dict]. so need to get the dictionary out of the data.
data=data[0]
#initialize rss_description as a form of the table
rss_description = '<![CDATA[<TABLE border style=\"border-collapse: collapse;\">'
rss_description += '<TR><TH>workflow name</TH><TH>jobs</TH>\
<TH>succeeded</TH><TH>success</TH><TH>attempts</TH>\
<TH>phase</TH><TH>dispatched</TH><TH>depend</TH>\
<TH>active</TH><TH>update date</TH><TH>current date</TH></TR><TR>'
#store only the needed information
specific_keys = ['workflow_name','jobs','succeeded','success','attempts','phase','dispatched','auger_depend','auger_active','update_ts','current_ts']
for i in specific_keys:
dummy= data.get(i)
if i == 'success':
if data.get('succeeded'):
dummy = '%2.1f'%(100.*data.get('succeeded')/data.get('jobs')) +' %'
else:
dummy ='0'
if dummy == None:
dummy = '0'
if i[-3:]=='_ts':
dummy = str(time.strftime("%a, %d %b %Y %H:%M:%S EST", time.localtime(data.get(i)/1000.)))+'\t + %03d ms'%(data.get(i)%1000)
dummy= str(dummy)
rss_description += '<TD>' + dummy+'</TD>'
rss_description += '</TR></TABLE>]]>'
if MODE =='initialize':
main=rss_main(title="CLAS 12 Workflow")
main.add_item(title=str(data["workflow_name"]),description=rss_description, pubDate=time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(data["update_ts"]/1000)) )
main.savexml(filename)
if MODE =='add':
modified=rss_modify(filein=filename)
# b.tag_channel[3][2].text ='new description'
modified.add_item(title=str(data["workflow_name"]),description=rss_description, pubDate=time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(data["update_ts"]/1000)) )
modified.savexml(filename)