<commit_before>import json
import os
import sys
import requests

metadata_file_path = 'ert-tile/metadata.json'
pivnet_token = os.environ['PIVNET_TOKEN']

with open(metadata_file_path, 'r') as metadata_ert_raw:
    metadata_ert = json.load(metadata_ert_raw)
    # print("metadata:")
    # print(json.dumps(metadata_ert, indent="  "))

    ert_product_files = metadata_ert.get("ProductFiles")
    ert_tile_product_file = None
    for product_file in ert_product_files:
        if product_file.get("File") == "PCF Elastic Runtime":
            ert_tile_product_file = product_file
    if not ert_tile_product_file:
        print("Unable to find ert tile in product ert release file list")
        sys.exit(1)

    dependecies = metadata_ert.get("Dependencies")
    stemcell_dependency = None
    for dependency in dependecies:
        dependency_release = dependency.get("Release")
        if dependency_release.get("Product").get("Name") == "Stemcells for PCF":
            stemcell_dependency = dependency_release
    if not stemcell_dependency:
        print("Unable to find stemcell in dependency list")
        sys.exit(1)

    stemcell_pivnet_url = "https://network.pivotal.io/api/v2/products/stemcells/releases/{}".format(
        stemcell_dependency.get("ID")
    )

    stemcell_response = requests.get(
        url=stemcell_pivnet_url,
        headers={
            'Authorization': 'Token {}'.format(pivnet_token),
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    )
    if stemcell_response.status_code != 200:
        print("Failed getting stemcell data from data")
        print(stemcell_response)
        print(stemcell_response.status_code)
        sys.exit(1)
    metadata_stemcell = stemcell_response.json()

    stemcell_product_file = None
    for product_file in metadata_stemcell.get("product_files"):
        if "for AWS" in product_file.get("name"):
            stemcell_product_file = product_file
    if not stemcell_product_file:
        print("Unable to find stemcell in product stemcell release file list")
        sys.exit(1)

    ert_release = metadata_ert.get("Release")

    config = {
        "ert": {
            "id": ert_release.get("ID"),
            "version": ert_release.get("Version"),
            "releaseDate": ert_release.get("ReleaseDate"),
            "sha256": ert_tile_product_file.get("SHA256")
        },
        "stemcell": {
            "id": stemcell_dependency.get("ID"),
            "version": stemcell_dependency.get("Version"),
            "releaseDate": metadata_stemcell.get("release_date"),
            "sha256": stemcell_product_file.get("sha256"),
        }
    }

    with("version_config.json") as config_output_file:
        json.dump(config, config_output_file, indent="  ")<commit_msg>More small bug fixes<commit_after>import json
import os
import sys
import requests

metadata_file_path = '../ert-tile/metadata.json'
pivnet_token = os.environ['PIVNET_TOKEN']

with open(metadata_file_path, 'r') as metadata_ert_raw:
    metadata_ert = json.load(metadata_ert_raw)
    print("metadata:")
    print(json.dumps(metadata_ert, indent="  "))

    ert_product_files = metadata_ert.get("ProductFiles")
    ert_tile_product_file = None
    for product_file in ert_product_files:
        if product_file.get("File") == "PCF Elastic Runtime":
            ert_tile_product_file = product_file
    if not ert_tile_product_file:
        print("Unable to find ert tile in product ert release file list")
        sys.exit(1)

    dependecies = metadata_ert.get("Dependencies")
    stemcell_dependency = None
    for dependency in dependecies:
        dependency_release = dependency.get("Release")
        if dependency_release.get("Product").get("Name") == "Stemcells for PCF":
            stemcell_dependency = dependency_release
    if not stemcell_dependency:
        print("Unable to find stemcell in dependency list")
        sys.exit(1)

    stemcell_pivnet_url = "https://network.pivotal.io/api/v2/products/stemcells/releases/{}".format(
        stemcell_dependency.get("ID")
    )

    stemcell_response = requests.get(
        url=stemcell_pivnet_url,
        headers={
            'Authorization': 'Token {}'.format(pivnet_token),
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        }
    )
    if stemcell_response.status_code != 200:
        print("Failed getting stemcell data from data")
        print(stemcell_response)
        print(stemcell_response.status_code)
        sys.exit(1)
    metadata_stemcell = stemcell_response.json()

    stemcell_product_file = None
    for product_file in metadata_stemcell.get("product_files"):
        if "for AWS" in product_file.get("name"):
            stemcell_product_file = product_file
    if not stemcell_product_file:
        print("Unable to find stemcell in product stemcell release file list")
        sys.exit(1)

    ert_release = metadata_ert.get("Release")

    config = {
        "ert": {
            "id": ert_release.get("ID"),
            "version": ert_release.get("Version"),
            "releaseDate": ert_release.get("ReleaseDate"),
            "sha256": ert_tile_product_file.get("SHA256")
        },
        "stemcell": {
            "id": stemcell_dependency.get("ID"),
            "version": stemcell_dependency.get("Version"),
            "releaseDate": metadata_stemcell.get("release_date"),
            "sha256": stemcell_product_file.get("sha256"),
        }
    }

    with open("version_config.json", "w") as config_output_file:
        json.dump(config, config_output_file, indent="  ")
{'fraction_non_alphanumeric': 0.11205976520811099, 'fraction_numerical': 0.007114905727499111, 'mean_word_length': 2.9794762915782025, 'pattern_counts': {'":': 24, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1651669', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1665, 'n_words': 329}