Add option menu alongside arguments for ease of use

This commit is contained in:
Rim 2023-12-25 19:44:48 -05:00
parent a41ccd0e15
commit 7208e07bad
2 changed files with 125 additions and 59 deletions

4
.gitignore vendored
View File

@ -1,6 +1,8 @@
__pycache__ __pycache__
uninstall.* uninstall.*
venv.* venv.*
/cod_pics
/venv /venv
/HTML
/stats /stats
/userInfo.json
/cookie*

View File

@ -125,6 +125,24 @@ def get_and_save_data(player_name=None, all_stats=False, season_loot=False, iden
settings = api.Me.settings() settings = api.Me.settings()
save_to_file(settings, 'settings.json') save_to_file(settings, 'settings.json')
def display_menu():
print("Please choose an option:")
print("1) Get all stats")
print("2) Get season loot")
print("3) Get identities")
print("4) Get map list")
print("5) Get general information")
print("6) Get friend feed")
print("7) Get event feed")
print("8) Get COD Point balance")
print("9) Get connected accounts")
print("10) Get account settings")
print("11) Beautify all data")
print("12) Split matches into separate files")
print("0) Exit")
choice = input("Enter your choice: ")
return int(choice)
# Save results to a JSON file inside the stats directory # Save results to a JSON file inside the stats directory
def recursive_key_replace(obj): def recursive_key_replace(obj):
if isinstance(obj, dict): if isinstance(obj, dict):
@ -184,7 +202,6 @@ def replace_time_and_duration_recursive(data):
""" """
Recursively replace epoch times for specific keys in a nested dictionary or list. Recursively replace epoch times for specific keys in a nested dictionary or list.
""" """
time_keys = ["timePlayedTotal", "timePlayed", "objTime", "time", "timeProne", time_keys = ["timePlayedTotal", "timePlayed", "objTime", "time", "timeProne",
"timeSpentAsPassenger", "timeSpentAsDriver", "timeOnPoint", "timeSpentAsPassenger", "timeSpentAsDriver", "timeOnPoint",
"timeWatchingKillcams", "timeCrouched", "timesSelectedAsSquadLeader", "timeWatchingKillcams", "timeCrouched", "timesSelectedAsSquadLeader",
@ -193,25 +210,20 @@ def replace_time_and_duration_recursive(data):
if isinstance(data, list): if isinstance(data, list):
for item in data: for item in data:
replace_time_and_duration_recursive(item) replace_time_and_duration_recursive(item)
elif isinstance(data, dict): elif isinstance(data, dict):
for key, value in data.items(): for key, value in data.items():
if key in time_keys: if key in time_keys:
data[key] = convert_duration_seconds(value) data[key] = convert_duration_seconds(value)
elif key == "utcStartSeconds": elif key == "utcStartSeconds":
data[key] = epoch_to_human_readable(value) data[key] = epoch_to_human_readable(value)
# For EST conversion: # For EST conversion:
# data[key] = epoch_to_human_readable(value, "EST") # data[key] = epoch_to_human_readable(value, "EST")
elif key == "utcEndSeconds": elif key == "utcEndSeconds":
data[key] = epoch_to_human_readable(value) data[key] = epoch_to_human_readable(value)
# For EST conversion: # For EST conversion:
# data[key] = epoch_to_human_readable(value, "EST") # data[key] = epoch_to_human_readable(value, "EST")
elif key == "duration": elif key == "duration":
data[key] = convert_duration_milliseconds(value) data[key] = convert_duration_milliseconds(value)
else: else:
replace_time_and_duration_recursive(value) replace_time_and_duration_recursive(value)
@ -332,6 +344,57 @@ def main():
- Enter the value when prompted - Enter the value when prompted
""" """
# Check if the script is run without any additional command-line arguments
if len(sys.argv) == 1:
if os.path.exists(COOKIE_FILE):
with open(COOKIE_FILE, 'r') as f:
api_key = f.read().strip()
else:
api_key = input("Please enter your ACT_SSO_COOKIE: ")
with open(COOKIE_FILE, 'w') as f:
f.write(api_key)
player_name = input("Please enter the player's username (with #1234567): ")
api.login(api_key)
while True:
choice = display_menu()
if choice == 1:
get_and_save_data(player_name, all_stats=True)
elif choice == 2:
get_and_save_data(player_name, season_loot=True)
elif choice == 3:
get_and_save_data(player_name, identities=True)
elif choice == 4:
get_and_save_data(player_name, maps=True)
elif choice == 5:
get_and_save_data(player_name, info=True)
elif choice == 6:
get_and_save_data(player_name, friendFeed=True)
elif choice == 7:
get_and_save_data(player_name, eventFeed=True)
elif choice == 8:
get_and_save_data(player_name, cod_points=True)
elif choice == 9:
get_and_save_data(player_name, connected_accounts=True)
elif choice == 10:
get_and_save_data(player_name, settings=True)
elif choice == 11:
beautify_data()
beautify_match_data()
beautify_feed_data()
clean_json_files('friendFeed.json', 'eventFeed.json')
elif choice == 12:
split_matches_into_files()
elif choice == 0:
print("Exiting...")
break
else:
print("Invalid choice. Please try again.")
continue
break
else:
parser = argparse.ArgumentParser(description="Detailed Modern Warfare (2019) Statistics Tool", epilog=help_text, formatter_class=argparse.RawDescriptionHelpFormatter) parser = argparse.ArgumentParser(description="Detailed Modern Warfare (2019) Statistics Tool", epilog=help_text, formatter_class=argparse.RawDescriptionHelpFormatter)
# Group related arguments # Group related arguments
@ -380,6 +443,7 @@ def main():
elif args.clean: elif args.clean:
beautify_data() beautify_data()
beautify_match_data() beautify_match_data()
beautify_feed_data()
clean_json_files('friendFeed.json', 'eventFeed.json') clean_json_files('friendFeed.json', 'eventFeed.json')
elif args.clean_friend_feed: elif args.clean_friend_feed:
clean_json_files('friendFeed.json') clean_json_files('friendFeed.json')