fix(cod_api_tool.py): fix time key sorting, fix epoch second conversion & update regex stub

This commit is contained in:
Rim 2025-02-28 19:17:03 -05:00
parent 32a5035328
commit 5273d8c0c6

View File

@ -291,7 +291,7 @@ class CodStatsManager:
def clean_json_files(self, *filenames):
"""Clean JSON files by removing HTML-like tags and entities."""
regex_pattern = r'<span class="|</span>|">|mp-stat-items|kills-value|headshots-value|username|game-mode|kdr-value|accuracy-value'
regex_pattern = r'<span class="|</span>|">|mp-stat-items|kills-value|headshots-value|username|game-mode|kdr-value|accuracy-value|defends-value'
replace = ''
for filename in filenames:
@ -383,15 +383,22 @@ class CodStatsManager:
"timeWatchingKillcams", "timeCrouched", "timesSelectedAsSquadLeader",
"longestTimeSpentOnWeapon", "avgLifeTime", "percentTimeMoving"
]
date_keys = ["date", "updated", "originalDate"]
date_keys = ["date", "updated", "originalDate", "dateAdded"]
if isinstance(data, list):
# Sort lists containing items with dateAdded
if data and isinstance(data[0], dict) and "dateAdded" in data[0]:
data.sort(key=lambda x: x.get("dateAdded", 0), reverse=True)
for item in data:
self._replace_time_and_duration_recursive(item, timezone)
elif isinstance(data, dict):
for key, value in data.items():
if key in date_keys:
data[key] = self._epoch_milli_to_human_readable(value, timezone)
if key == "dateAdded":
data[key] = self._epoch_to_human_readable(value, timezone)
else:
data[key] = self._epoch_milli_to_human_readable(value, timezone)
elif key in time_keys:
data[key] = self._convert_duration_seconds(value)
elif key == "utcStartSeconds":
@ -418,13 +425,13 @@ class CodStatsManager:
dt_object = datetime.datetime.utcfromtimestamp(epoch_timestamp)
return self._format_datetime(dt_object, timezone)
def _format_datetime(self, dt_object, timezone):
"""Format datetime object based on timezone."""
timezone_offsets = {
'GMT': 0,
'EST': -4,
'CST': -5,
'EST': -5, # Changed from -4 to -5 for Eastern Standard Time
'CST': -6, # Updated for consistency
'PST': -8
}
@ -432,7 +439,7 @@ class CodStatsManager:
raise ValueError(f"Unsupported timezone: {timezone}")
# Apply timezone offset
dt_object -= datetime.timedelta(hours=timezone_offsets[timezone])
dt_object = dt_object + datetime.timedelta(hours=timezone_offsets[timezone])
# Format date string
return f"{timezone}: {dt_object.strftime('%A, %B %d, %Y %I:%M:%S %p')}"