def process_rek_results()

in src/process_results/main.py [0:0]


def process_rek_results(rek_job_id, rek_status, video_processed):
    output_bucket = video_processed['S3Bucket']
    output_filename = get_output_filename(video_processed['S3ObjectName'])

    if rek_status != "SUCCEEDED":
        write_output(output_bucket, output_filename, f'Text detection failed: {rek_status}')
    else:
        ad_placement_finder = AdOpportunites(min_seconds_needed)

        paginationToken = ''
        finished = False
        maxResults = 100
        rek = boto3.client('rekognition', region_name=region)

        while not finished:
            response = rek.get_text_detection(JobId=rek_job_id,
                                              MaxResults=maxResults,
                                              NextToken=paginationToken)

            # we need to know the total video length to
            # check if there's an available ad slot at the end of the video
            total_video_length = response['VideoMetadata']['DurationMillis']
            ad_placement_finder.set_video_length(total_video_length)

            for textDetection in response['TextDetections']:
                text = textDetection['TextDetection']
                timestamp = int(textDetection['Timestamp'])
                found_type = str(text['Type'])
                found_string = text['DetectedText']
                bounding_box = text['Geometry']['BoundingBox']

                if found_type == "WORD":
                    print(f'Found word {found_string} at timestamp {timestamp} with width {bounding_box["Width"]} and confidence {text["Confidence"]}')
                    if is_word_box_large_enough(bounding_box):
                        ad_placement_finder.add_text_presence(timestamp)

            if 'NextToken' in response:
                paginationToken = response['NextToken']
            else:
                finished = True

        # dump out the possible ad placements
        write_output(output_bucket, output_filename, ad_placement_finder.get_available_placement_text())