I'm stuck on a simple issue:
I get through urllib
a JSON app list which looks like this :
"completedapps" : [ {
"starttime" : 1520863179923,
"id" : "app-20180312145939-0183",
"name" : "IE_Traitement_3",
"cores" : 1,
"user" : "root",
"memoryperslave" : 1024,
"submitdate" : "Mon Mar 12 14:59:39 CET 2018",
"state" : "FINISHED",
"duration" : 212967
}, {
"starttime" : 1520863398147,
"id" : "app-20180312150318-0186",
"name" : "IE_Traitement_3",
"cores" : 1,
"user" : "root",
"memoryperslave" : 1024,
"submitdate" : "Mon Mar 12 15:03:18 CET 2018",
"state" : "FINISHED",
"duration" : 6321
}, {
"starttime" : 1520863387941,
"id" : "app-20180312150307-0185",
"name" : "IE_Traitement_0A",
"cores" : 1,
"user" : "root",
"memoryperslave" : 1024,
"submitdate" : "Mon Mar 12 15:03:07 CET 2018",
"state" : "FINISHED",
"duration" : 149536
}, { ... }]
I would like to get the most recent element for app named "IE_Traitement_OA", so I begin with filtering my JSON like this :
[app for app in parsedjson['completedapps'] if app['name'] == "IE_Traitement_OA"]
But I'm stuck now, I have no idea about how could I get the most recent "app" ? I think I have to use the starttime
or submitdate
field but I don't know how to deal with that. Could you help me?