<jupyter_start><jupyter_text>Check botscore of friends/followers of bots<jupyter_code>users_to_check_botscore = db_helper.getDataframeFromQuery(
    db_helper.connect_db(), 
    """
    select 
        c.t_usr_id_ego, 
        c.t_usr_id_conn, 
        c.conn_type
    from
        bot b,
        connections c
    where b.twitter_user_id = c.t_usr_id_ego
    ;"""
)
users_to_check_botscore.drop_duplicates(inplace=True)
twitter_id_alignment_dict = {
    "<BOT_1_ID>": "Left",
    "<BOT_2_ID>": "Left",
    # ...
    "<BOT_4_ID>": "C.Left",
    "<BOT_5_ID>": "C.Left",
    # ...
    "<BOT_n+1_ID>": "Right",
    "<BOT_n+2_ID>": "Right",
}
users_to_check_botscore["seed"] = users_to_check_botscore.t_usr_id_ego.apply(
    twitter_id_alignment_dict.get
)

users_to_check_botscore.conn_type = users_to_check_botscore.conn_type.apply(
    lambda x: "follower" if x else "friend"
)<jupyter_output><empty_output><jupyter_text>saving bot scores to json files for later processing<jupyter_code>tw_keys = {
    "consumer_key": "<replace_here>",
    "consumer_secret": "<replace_here>",
    "access_token": "<replace_here>",
    "access_token_secret": "<replace_here>",
    "mashape_key": "<replace_here>",
}
check_botscore = RetrieveBotscore(tw_keys)
check_botscore.check_botometer_scores(users_to_check_botscore.t_usr_id_conn.unique())<jupyter_output><empty_output><jupyter_text>Reading bot scores from json file<jupyter_code>json_file = "<FILL_HERE_THE_NAME_OF_THE_FILE_SAVED_IN_THE_PREVIOUS_STEP>"
botscore_measurements = check_botscore.loadJson(json_file)[[
    "user_id_str","user_screen_name","scores_english"
]]
botscore_measurements = botscore_measurements.join(
    pd.DataFrame(users_to_check_botscore,columns=["user_id_str"]).set_index("user_id_str"),
    on="user_id_str",
    how="outer"
)
botscore_measurements = botscore_measurements[~botscore_measurements.user_id_str.isna()]
botscore_measurements.set_index("user_id_str", inplace=True)
botscore_dict = botscore_measurements.scores_english.to_dict()

connections_overall_botscores = users_to_check_botscore.groupby(
    ["conn_type","seed"]
).apply(
    lambda x: pd.Series([
        botscore_dict.get(str(user_id)) 
        for user_id in pd.Series(np.concatenate(x.t_usr_id_conn.values)).unique()
    ]).dropna().to_list()
)

connections_overall_botscores.to_csv("../data/connections_seeds_unique_botscores.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12952936276551436, 'fraction_numerical': 0.0024989587671803417, 'mean_word_length': 5.709497206703911, 'pattern_counts': {'":': 11, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 0, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '524849', 'license': 'MIT', 'n_tokens_mistral': 934, 'n_tokens_neox': 918, 'n_words': 102, 'path': 'data/retrieving_botscore.ipynb', 'repo_name': 'IUNetSci/DrifterBot', 'size': '2401'}