<s> import requests <EOL> from datetime import datetime <EOL> def GetScanExecutions ( config , scan_id ) : <EOL> """<STR_LIT>""" <EOL> results = { } <EOL> url = "<STR_LIT>" . format ( config [ '<STR_LIT>' ] , scan_id ) <EOL> headers = { "<STR_LIT>" : "<STR_LIT:application/json>" } <EOL> try : <EOL> r = requests . get ( url , <EOL> headers = headers , <EOL> auth = ( config [ '<STR_LIT>' ] , '<STR_LIT>' ) ) <EOL> r . raise_for_status ( ) <EOL> except : <EOL> raise ValueError ( "<STR_LIT>" % ( r . status_code , r . url ) ) <EOL> try : <EOL> data = r . json ( ) <EOL> except : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> else : <EOL> results = { '<STR_LIT>' : None , '<STR_LIT>' : [ ] } <EOL> for item in data : <EOL> cd = datetime . fromtimestamp ( item [ '<STR_LIT>' ] ) <EOL> create_date = cd . strftime ( '<STR_LIT>' ) <EOL> if item [ '<STR_LIT>' ] is not None : <EOL> fd = datetime . fromtimestamp ( item [ '<STR_LIT>' ] ) <EOL> finish_date = fd . strftime ( '<STR_LIT>' ) <EOL> duration = str ( fd - cd ) <EOL> else : <EOL> finish_date = "<STR_LIT:->" <EOL> duration = str ( datetime . now ( ) . replace ( microsecond = <NUM_LIT:0> ) - cd ) <EOL> results [ '<STR_LIT>' ] . append ( { "<STR_LIT:id>" : item [ '<STR_LIT:id>' ] , <EOL> "<STR_LIT>" : item [ '<STR_LIT>' ] , <EOL> "<STR_LIT>" : create_date , <EOL> "<STR_LIT>" : finish_date , <EOL> "<STR_LIT>" : duration } ) <EOL> results [ '<STR_LIT>' ] . sort ( reverse = True ) <EOL> results [ '<STR_LIT>' ] = results [ '<STR_LIT>' ] [ <NUM_LIT:0> : <NUM_LIT:10> ] <EOL> for item in results [ '<STR_LIT>' ] : <EOL> if item [ '<STR_LIT>' ] is False : <EOL> results [ '<STR_LIT>' ] = item [ '<STR_LIT:id>' ] <EOL> break <EOL> return results </s>
