chore(cod_api_tool.py): remove whitespace & add try except for cleaning match_info and stats files
This commit is contained in:
parent
61b910ab45
commit
dfc647e500
@ -258,64 +258,81 @@ class CodStatsManager:
|
||||
self.beautify_match_data(timezone, player_name)
|
||||
self.beautify_feed_data(timezone)
|
||||
self.clean_json_files('friendFeed.json', 'eventFeed.json')
|
||||
print("All data beautified successfully.")
|
||||
print("Data beautified successfully.")
|
||||
|
||||
def beautify_stats_data(self, timezone='GMT', player_name=None):
|
||||
"""Beautify stats data."""
|
||||
if player_name:
|
||||
file_name = f'stats-{self._extract_player_name(player_name)}.json'
|
||||
else:
|
||||
file_name = 'stats.json'
|
||||
if player_name is None:
|
||||
print("Please specify a Player Name to sort Stats")
|
||||
return 0
|
||||
try:
|
||||
if player_name:
|
||||
file_name = f'stats-{self._extract_player_name(player_name)}.json'
|
||||
# else:
|
||||
# file_name = 'stats.json'
|
||||
|
||||
file_path = os.path.join(STATS_DIR, file_name)
|
||||
if not os.path.exists(file_path):
|
||||
print(f"File {file_path} not found. Skipping beautification.")
|
||||
return
|
||||
file_path = os.path.join(STATS_DIR, file_name)
|
||||
if not os.path.exists(file_path):
|
||||
print(f"File {file_path} not found. Skipping beautification.")
|
||||
return
|
||||
|
||||
with open(file_path, 'r') as file:
|
||||
data = json.load(file)
|
||||
with open(file_path, 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
# Convert times and durations
|
||||
self._replace_time_and_duration_recursive(data, timezone)
|
||||
# Convert times and durations
|
||||
self._replace_time_and_duration_recursive(data, timezone)
|
||||
|
||||
# Replace keys with more readable names
|
||||
data = self._recursive_key_replace(data)
|
||||
# Replace keys with more readable names
|
||||
data = self._recursive_key_replace(data)
|
||||
|
||||
# Sort data by relevant metrics
|
||||
data = self._sort_data(data)
|
||||
# Sort data by relevant metrics
|
||||
data = self._sort_data(data)
|
||||
|
||||
# Save modified data
|
||||
with open(file_path, 'w') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
# Save modified data
|
||||
with open(file_path, 'w') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
|
||||
print(f"Keys sorted and replaced in {file_path}.")
|
||||
print(f"Keys sorted and replaced in {file_path}.")
|
||||
|
||||
except Exception as e:
|
||||
print("An error occurred while processing match data.")
|
||||
return 0
|
||||
|
||||
def beautify_match_data(self, timezone='GMT', player_name=None):
|
||||
"""Beautify match data."""
|
||||
if player_name:
|
||||
file_name = f'match_info-{self._extract_player_name(player_name)}.json'
|
||||
else:
|
||||
file_name = 'match_info.json'
|
||||
if player_name is None:
|
||||
print("Please specify a Player Name to sort Match Info")
|
||||
return 0
|
||||
|
||||
file_path = os.path.join(STATS_DIR, file_name)
|
||||
if not os.path.exists(file_path):
|
||||
print(f"File {file_path} not found. Skipping beautification.")
|
||||
return
|
||||
try:
|
||||
if player_name:
|
||||
file_name = f'match_info-{self._extract_player_name(player_name)}.json'
|
||||
# else:
|
||||
# file_name = 'match_info.json'
|
||||
|
||||
with open(file_path, 'r') as file:
|
||||
data = json.load(file)
|
||||
file_path = os.path.join(STATS_DIR, file_name)
|
||||
if not os.path.exists(file_path):
|
||||
print(f"File {file_path} not found. Skipping beautification.")
|
||||
return
|
||||
|
||||
# Convert times and durations
|
||||
self._replace_time_and_duration_recursive(data, timezone)
|
||||
with open(file_path, 'r') as file:
|
||||
data = json.load(file)
|
||||
|
||||
# Replace keys with more readable names
|
||||
data = self._recursive_key_replace(data)
|
||||
# Convert times and durations
|
||||
self._replace_time_and_duration_recursive(data, timezone)
|
||||
|
||||
# Save modified data
|
||||
with open(file_path, 'w') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
# Replace keys with more readable names
|
||||
data = self._recursive_key_replace(data)
|
||||
|
||||
print(f"Keys replaced in {file_path}.")
|
||||
# Save modified data
|
||||
with open(file_path, 'w') as file:
|
||||
json.dump(data, file, indent=4)
|
||||
|
||||
print(f"Keys replaced in {file_path}.")
|
||||
|
||||
except Exception as e:
|
||||
print("An error occurred while processing match data.")
|
||||
return 0
|
||||
|
||||
def beautify_feed_data(self, timezone='GMT', player_name=None):
|
||||
"""Beautify feed data files."""
|
||||
|
Loading…
x
Reference in New Issue
Block a user