fix(cod_api_tool.py): fix time key sorting, fix epoch second conversion & update regex stub
This commit is contained in:
parent
32a5035328
commit
5273d8c0c6
@ -291,7 +291,7 @@ class CodStatsManager:
|
|||||||
|
|
||||||
def clean_json_files(self, *filenames):
|
def clean_json_files(self, *filenames):
|
||||||
"""Clean JSON files by removing HTML-like tags and entities."""
|
"""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 = ''
|
replace = ''
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
@ -383,14 +383,21 @@ class CodStatsManager:
|
|||||||
"timeWatchingKillcams", "timeCrouched", "timesSelectedAsSquadLeader",
|
"timeWatchingKillcams", "timeCrouched", "timesSelectedAsSquadLeader",
|
||||||
"longestTimeSpentOnWeapon", "avgLifeTime", "percentTimeMoving"
|
"longestTimeSpentOnWeapon", "avgLifeTime", "percentTimeMoving"
|
||||||
]
|
]
|
||||||
date_keys = ["date", "updated", "originalDate"]
|
date_keys = ["date", "updated", "originalDate", "dateAdded"]
|
||||||
|
|
||||||
if isinstance(data, list):
|
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:
|
for item in data:
|
||||||
self._replace_time_and_duration_recursive(item, timezone)
|
self._replace_time_and_duration_recursive(item, timezone)
|
||||||
elif isinstance(data, dict):
|
elif isinstance(data, dict):
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
if key in date_keys:
|
if key in date_keys:
|
||||||
|
if key == "dateAdded":
|
||||||
|
data[key] = self._epoch_to_human_readable(value, timezone)
|
||||||
|
else:
|
||||||
data[key] = self._epoch_milli_to_human_readable(value, timezone)
|
data[key] = self._epoch_milli_to_human_readable(value, timezone)
|
||||||
elif key in time_keys:
|
elif key in time_keys:
|
||||||
data[key] = self._convert_duration_seconds(value)
|
data[key] = self._convert_duration_seconds(value)
|
||||||
@ -423,8 +430,8 @@ class CodStatsManager:
|
|||||||
"""Format datetime object based on timezone."""
|
"""Format datetime object based on timezone."""
|
||||||
timezone_offsets = {
|
timezone_offsets = {
|
||||||
'GMT': 0,
|
'GMT': 0,
|
||||||
'EST': -4,
|
'EST': -5, # Changed from -4 to -5 for Eastern Standard Time
|
||||||
'CST': -5,
|
'CST': -6, # Updated for consistency
|
||||||
'PST': -8
|
'PST': -8
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +439,7 @@ class CodStatsManager:
|
|||||||
raise ValueError(f"Unsupported timezone: {timezone}")
|
raise ValueError(f"Unsupported timezone: {timezone}")
|
||||||
|
|
||||||
# Apply timezone offset
|
# Apply timezone offset
|
||||||
dt_object -= datetime.timedelta(hours=timezone_offsets[timezone])
|
dt_object = dt_object + datetime.timedelta(hours=timezone_offsets[timezone])
|
||||||
|
|
||||||
# Format date string
|
# Format date string
|
||||||
return f"{timezone}: {dt_object.strftime('%A, %B %d, %Y %I:%M:%S %p')}"
|
return f"{timezone}: {dt_object.strftime('%A, %B %d, %Y %I:%M:%S %p')}"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user