def clean_resource_tags()

in clone_mediaconvert_resources/clone_mediaconvert_resources.py [0:0]


def clean_resource_tags(arns, file):
    resource_type = arns[0]['Arn'].split('/')[0].split(":")[5]
    clean_tags = []
    for arn in arns:
        resource_name = arn['Arn'].split('/')[1]
        tags = {}
        for k, v in arn['Tags'].items():
            tags[k] = v
        clean_tags.append({resource_name: tags})
    if file == "single":
        if not os.path.exists(resource_type):
            create_directory(resource_type)

        file_path = resource_type + "/resource.json"
        with open(file_path, 'w') as output_file:
            json.dump(clean_tags, output_file)

    else:

        t = time.time()
        working_directory = resource_type + "_resource_tags_" + str(int(t))
        create_directory(working_directory)

        for c_tags in clean_tags:
            for tag in c_tags:
                filename = tag + ".json"
                with open(working_directory + '/resource_tag_' + filename, 'w+') as output_file:
                    json.dump(c_tags, output_file)