def __write_vmap()

in vmap_generation/app.py [0:0]


def __write_vmap(slots, bucket, key):
    vmap = VMAP()
    i = 1
    for slot in slots:
        # Merging labels from before and after the slot into a single list
        before_labels = [label['Name'] for label in slot['Context']['Labels']['Before']]
        after_labels = [label['Name'] for label in slot['Context']['Labels']['After']]
        labels = before_labels + list(set(after_labels) - set(before_labels))
        # Adding ad break to VMAP file
        ad_break = vmap.attachAdBreak({
            'timeOffset': __format_timedelta(datetime.timedelta(seconds=float(slot['Timestamp']))),
            'breakType': 'linear',
            'breakId': 'midroll-{}'.format(i)
        })
        # Adding VAST ad source 
        vast = VAST()
        ad_break.attachAdSource(
            'midroll-{}-ad-1'.format(i),
            'false',
            'true',
            'VASTAdData',
            vast)
        ad = vast.attachAd({
            'id': str(i),
            'structure': 'inline',
            'AdSystem': {'name': '2.0'},
            'AdTitle': 'midroll-{}-ad-1'.format(i)
        })
        ad.attachImpression({})
        creative = ad.attachCreative('Linear', {
            'Duration' : '00:00:15'
        })
        # Setting media file URL referencing the ad server, passing labels as parameters
        creative.attachMediaFile(__select_ad(labels), {
            'id': 'midroll-{}-ad-1'.format(i),
            'type': 'video/mp4',
            'delivery': 'progressive',
            'width': '1920',
            'height': '1080'
        })
        i += 1
    # Converting VMAP content to XML
    vmap_content = vmap.xml()
    print(vmap_content)
    # Putting VMAP file into dataplane bucket
    s3.put_object(
        Body=bytes(vmap_content),
        Bucket=bucket,
        Key=key
    )