""" This is a one-time fix script where we need to fix some content of the accounts created. """ # Imports: import os import pandas as pd from helpers import tcaoff from utils_v2.string import json from utils_v2.system import files # File paths: file_dir = files.get_file_directory(include_filename = False) proj_dir = files.get_parent_directory(file_dir, depth = 1) tcaoff_creds_file = os.path.join(proj_dir, "creds", "tcaoff.json") # Load the creds: tcaoff_creds = json.from_file(tcaoff_creds_file) # Log in: tcaoff.login(tcaoff_creds) # Load the team list: team_list = tcaoff.team_list(tcaoff_creds) # Loop through the list, # check if `applicantNotes` in `json_notes` is a string, # if it is a string, convert it to a dict/list and update the user: for team in team_list: # Extract info: json_notes = json.from_string(team.get("json_notes", {})) app_notes = json_notes.get("applicantNotes") if isinstance(app_notes, str): app_notes = json.from_string(app_notes) if not app_notes: continue # Fix the app notes: cosec_notes = app_notes.get("cosec", {}) print("COSEC NOTES:", cosec_notes) cosec_notes = { "User ID": cosec_notes.get("User ID", cosec_notes.get("UserID")), "User Name": cosec_notes.get("User Name", cosec_notes.get("UserName")), "Category Name": cosec_notes.get("Category Name", cosec_notes.get("CategoryName")), "Grade Name": cosec_notes.get("Grade Name", cosec_notes.get("GradeName")), "Branch Name": cosec_notes.get("Branch Name", cosec_notes.get("BranchName")), "Department Name": cosec_notes.get("Department Name", cosec_notes.get("DepartmentName")), "Direct Reporting": cosec_notes.get("Direct Reporting", cosec_notes.get("DirectReporting")), "Direct Reporting ID": cosec_notes.get("Direct Reporting ID", cosec_notes.get("DirectReportingID")), "Level-1 ID": cosec_notes.get("Level-1 ID", cosec_notes.get("Level-1ID")), } # Save the JSON Notes again: json_notes["applicantNotes"] = app_notes team["json_notes"] = json.to_string(json_notes, no_space = True) # Make a pandas DataFrame: team_df = pd.DataFrame(team_list) # Log out: tcaoff.logout(tcaoff_creds) # Show and save the DF: print(team_df[:10].to_string()) team_df[["user_id", "json_notes"]].to_csv(r"C:\Users\Khushal P Soonderji\Downloads\20260121_cosec_team_fix.csv", index = False)