<jupyter_start><jupyter_text>Players account info handler<jupyter_code>import time

from itertools import chain

import requests as req
import pandas as pd
import numpy as np

from settings import TOKEN<jupyter_output><empty_output><jupyter_text>GoalRetrieve the account_id from the players account info becuase with it we can start retrieving the match history of each player  1. Import players pool data<jupyter_code>players_pool = pd.read_pickle("raw_data/players_pool.pkl")
players_pool.head()
id_list = players_pool["summonerId"].to_list()
id_list[0]<jupyter_output><empty_output><jupyter_text>2. Check how the api works<jupyter_code>def get_acc_info(summoner_id: str):
    
    url = f"https://euw1.api.riotgames.com/lol/summoner/v4/summoners/{summoner_id}?api_key={TOKEN}"
    res = req.get(url)
    
    return res.json()
get_acc_info(id_list[0])<jupyter_output><empty_output><jupyter_text>- We are interested on storing the accountId value into the players data  3. Adjust the function to retrieve each individual account information- max 100 request every 2 minutes<jupyter_code>def get_accounts_info(id_list: list, token: str, path: str, start=0, end=0) -> pd.DataFrame:
    container = []
    base_url = "https://euw1.api.riotgames.com/lol/summoner/v4/summoners"
    n_requests = 0
    while start < end:
        # request account info for each summoner_id
        for i in range(start, end):
            # control the number of requests
            if n_requests >= 100:
                print(f"Number of Entries so far: {len(container)}")
                n_requests = 0
                time.sleep(121)

            # make request
            url = f"{base_url}/{id_list[i]}?api_key={token}"
            res = req.get(url)
            if res.status_code == 200:
                container.append(res.json())
                # update position
                start += 1
            else:
                # if error save to csv
                pd.DataFrame(container).to_csv(
                    f"{path}/fragmented_data/account_info_{start}.pkl", index=False)
                print(f"Something went wrong {res.status_code}")
                break
            # update the number of requests
            n_requests += 1
    print(f"Done, number of elements: {len(container)}")
    # return useful data
    container = pd.DataFrame(container).rename(columns={"id": "summonerId"})
    container = container[["summonerId", "accountId"]]
    container.to_pickle(f"{path}/account_info.pkl", protocol=4)
    return f"File saved at {path}/account_info.pkl"<jupyter_output><empty_output><jupyter_text>- Execute the function and hope for the best :D<jupyter_code>get_accounts_info(id_list, TOKEN, "raw_data", 0, 100)<jupyter_output>Done, number of elements: 100<jupyter_text>4. Check the data (already done in the function above this is just a step by step)<jupyter_code>first = pd.DataFrame(first)
print(f"Columns: {first.shape[1]} Rows: {first.shape[0]}\n")
print(f"Number of duplcated rows: {first.duplicated().sum()}\n")
print("Null values per column:\n")
print(first.isna().sum())<jupyter_output>Columns: 7 Rows: 200

Number of duplcated rows: 0

Null values per column:

id               0
accountId        0
puuid            0
name             0
profileIconId    0
revisionDate     0
summonerLevel    0
dtype: int64<jupyter_text>- Rename the id column to match summonerId on the player's pool<jupyter_code>first = first.rename(columns={"id": "summonerId"})<jupyter_output><empty_output><jupyter_text>- Select the keys we want<jupyter_code>first = first[["summonerId", "accountId"]]<jupyter_output><empty_output><jupyter_text>5. Merge the data from accounts to player_pool data<jupyter_code>players_pool = players_pool.merge(first, on="summonerId")
players_pool.head()<jupyter_output><empty_output><jupyter_text>6. Export the data<jupyter_code>players_pool.to_pickle("raw_data/players_pool_acc_id.pkl", protocol=4)<jupyter_output><empty_output><jupyter_text>As a function<jupyter_code>def merge_with(players_pool: pd.DataFrame, container: pd.DataFrame, path: str):
    players_pool = players_pool.merge(container, on="summonerId")
    players_pool.to_pickle(f"{path}/players_pool_account.pkl", protocol=4)
    return f"File saved at {path}/players_pool_account.pkl"
acc_info = pd.read_pickle("raw_data/account_info.pkl")
acc_info.head()
merge_with(players_pool, acc_info, "raw_data")<jupyter_output><empty_output><jupyter_text>- Check the file<jupyter_code>merged = pd.read_pickle("raw_data/players_pool_account.pkl")
merged.head()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11055166374781086, 'fraction_numerical': 0.012478108581436076, 'mean_word_length': 4.059800664451827, 'pattern_counts': {'":': 2, '<': 48, '<?xml version=': 0, '>': 49, '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}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '388688', 'license': 'MIT', 'n_tokens_mistral': 1597, 'n_tokens_neox': 1534, 'n_words': 338, 'path': 'notebooks/3_players_account_info.ipynb', 'repo_name': 'fs1m/lol_scouter', 'size': '4568'}