def _get_most_recent_snapshot(snapshots, max_snapshot_age_secs=None, now=None):
 if (len(snapshots) == 0):
  return None
 if (not now):
  now = datetime.datetime.utcnow()
 youngest_snapshot = max(snapshots, key=_get_snapshot_starttime)
 snapshot_start = datetime.datetime.strptime(youngest_snapshot.start_time, '%Y-%m-%dT%H:%M:%S.000Z')
 snapshot_age = (now - snapshot_start)
 if (max_snapshot_age_secs is not None):
  if (snapshot_age.total_seconds() > max_snapshot_age_secs):
   return None
 return youngest_snapshot

def _get_most_recent_snapshot ( snapshots , max_snapshot_age_secs = None , now = None ) : if ( len ( snapshots ) == 0 ) : return None if ( not now ) : now = datetime . datetime . utcnow ( ) youngest_snapshot = max ( snapshots , key = _get_snapshot_starttime ) snapshot_start = datetime . datetime . strptime ( youngest_snapshot . start_time , '%Y-%m-%dT%H:%M:%S.000Z' ) snapshot_age = ( now - snapshot_start ) if ( max_snapshot_age_secs is not None ) : if ( snapshot_age . total_seconds ( ) > max_snapshot_age_secs ) : return None return youngest_snapshot
gets the most recently created snapshot and optionally filters the result if the snapshot is too old .