<jupyter_start><jupyter_text>API Testing  01 - Get Heroes data from OpenDota API  Imports Libraries/Modules<jupyter_code>import pandas as pd
import requests
import json<jupyter_output><empty_output><jupyter_text>URLs<jupyter_code>HEROES_STATS_URL = 'https://api.opendota.com/api/heroStats'<jupyter_output><empty_output><jupyter_text>Get data from OpenDota API<jupyter_code>response = requests.get(f"{HEROES_STATS_URL}")
response
type(response)<jupyter_output><empty_output><jupyter_text>Convert JSON Data to Python List of Dictionaries<jupyter_code>heroes = json.loads(response.text)
type(heroes)
len(heroes) # 123 Heroes
# Show the first hero.
heroes[:1]<jupyter_output><empty_output><jupyter_text>Create a function that return a list of specific fields API<jupyter_code>def get_heroes_stats():
    try:
        response = requests.get(f"{HEROES_STATS_URL}")
    except Exception as error:
        return print("You have problem to get Heroes Stats:", error)
    else:
        heroes_stats = []
        temp = []
        heroes = json.loads(response.text)
        for hero in range(len(heroes)):
            temp.append(heroes[hero]["id"])
            temp.append(heroes[hero]["name"])
            temp.append(heroes[hero]["localized_name"])
            temp.append(heroes[hero]["primary_attr"])
            temp.append(heroes[hero]["attack_type"])
            temp.append("https://api.opendota.com"+heroes[hero]["img"])
            temp.append("https://api.opendota.com"+heroes[hero]["icon"])
            temp.append(heroes[hero]["base_health"])
            temp.append(heroes[hero]["base_health_regen"])
            temp.append(heroes[hero]["base_mana"])
            temp.append(heroes[hero]["base_mana_regen"])
            temp.append(heroes[hero]["base_armor"])
            temp.append(heroes[hero]["base_attack_min"])
            temp.append(heroes[hero]["base_attack_max"])
            temp.append(heroes[hero]["base_str"])
            temp.append(heroes[hero]["base_agi"])
            temp.append(heroes[hero]["base_int"])
            temp.append(heroes[hero]["str_gain"])
            temp.append(heroes[hero]["agi_gain"])
            temp.append(heroes[hero]["int_gain"])
            temp.append(heroes[hero]["attack_range"])
            temp.append(heroes[hero]["projectile_speed"])
            temp.append(heroes[hero]["move_speed"])
            temp.append(heroes[hero]["legs"])
            heroes_stats.append(temp)
            temp = []
        return heroes_stats
heroes = get_heroes_stats()
len(heroes)
type(heroes)
# Show all heroes and specifics fields.
heroes<jupyter_output><empty_output><jupyter_text>Print all heroes and specific fields<jupyter_code>for hero in range(len(heroes)):
    print(heroes[hero]["id"])
    print(heroes[hero]["name"])
    print(heroes[hero]["localized_name"])
    print(heroes[hero]["primary_attr"])
    print(heroes[hero]["attack_type"])
    print(heroes[hero]["img"])
    print(heroes[hero]["icon"])
    print(heroes[hero]["base_health"])
    print(heroes[hero]["base_health_regen"])
    print(heroes[hero]["base_mana"])
    print(heroes[hero]["base_mana_regen"])
    print(heroes[hero]["base_armor"])
    print(heroes[hero]["base_attack_min"])
    print(heroes[hero]["base_attack_max"])
    print(heroes[hero]["base_str"])
    print(heroes[hero]["base_agi"])
    print(heroes[hero]["base_int"])
    print(heroes[hero]["str_gain"])
    print(heroes[hero]["agi_gain"])
    print(heroes[hero]["int_gain"])
    print(heroes[hero]["attack_range"])
    print(heroes[hero]["projectile_speed"])
    print(heroes[hero]["move_speed"])
    print("\n")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15575807787903895, 'fraction_numerical': 0.0016570008285004142, 'mean_word_length': 4.219020172910663, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 3, '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}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '402531', 'license': 'MIT', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1235, 'n_words': 150, 'path': 'notebooks/api_testing.ipynb', 'repo_name': 'drigols/dota2learning', 'size': '3621'}