(datetime_target, cdxj_lines)
return best_line
Get the closest CDXJ entry for a datetime and URI-R
Get the closest CDXJ entry for a datetime and URI-R
Get the closest CDXJ entry for a datetime and URI - R
def get_cdxj_line_closest_to(datetime_target, cdxj_lines):
    """ Get the closest CDXJ entry for a datetime and URI-R """
    smallest_diff = float('inf')  # math.inf is only py3
    best_line = None
    datetime_target = int(datetime_target)
    for cdxj_line in cdxj_lines:
        dt = int(cdxj_line.split(' ')[1])
        diff = abs(dt - datetime_target)
        if diff < smallest_diff:
            smallest_diff = diff
            best_line = cdxj_line
    return best_line
def get_cdxj_line_closest_to ( datetime_target , cdxj_lines ) : smallest_diff = float ( 'inf' ) # math.inf is only py3 best_line = None datetime_target = int ( datetime_target ) for cdxj_line in cdxj_lines : dt = int ( cdxj_line . split ( ' ' ) [ 1 ] ) diff = abs ( dt - datetime_target ) if diff < smallest_diff : smallest_diff = diff best_line = cdxj_line return best_line