mirror of
https://github.com/Ahrimdon/detailed-cod-tracker.git
synced 2024-11-03 16:46:44 -05:00
Add time conversion for feeds
This commit is contained in:
parent
b4d305d531
commit
8d6f763f15
@ -229,12 +229,15 @@ def replace_time_and_duration_recursive(data):
|
|||||||
"timeSpentAsPassenger", "timeSpentAsDriver", "timeOnPoint",
|
"timeSpentAsPassenger", "timeSpentAsDriver", "timeOnPoint",
|
||||||
"timeWatchingKillcams", "timeCrouched", "timesSelectedAsSquadLeader",
|
"timeWatchingKillcams", "timeCrouched", "timesSelectedAsSquadLeader",
|
||||||
"longestTimeSpentOnWeapon", "avgLifeTime", "percentTimeMoving"]
|
"longestTimeSpentOnWeapon", "avgLifeTime", "percentTimeMoving"]
|
||||||
|
date_keys = ["date", "updated", "originalDate"]
|
||||||
|
|
||||||
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 date_keys:
|
||||||
|
data[key] = epoch_milli_to_human_readable(value)
|
||||||
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":
|
||||||
@ -250,6 +253,17 @@ def replace_time_and_duration_recursive(data):
|
|||||||
else:
|
else:
|
||||||
replace_time_and_duration_recursive(value)
|
replace_time_and_duration_recursive(value)
|
||||||
|
|
||||||
|
def epoch_milli_to_human_readable(epoch_millis):
|
||||||
|
"""
|
||||||
|
Convert epoch timestamp in milliseconds to human-readable date-time string.
|
||||||
|
"""
|
||||||
|
if isinstance(epoch_millis, str):
|
||||||
|
return epoch_millis # Already converted
|
||||||
|
|
||||||
|
dt_object = datetime.datetime.utcfromtimestamp(epoch_millis / 1000.0)
|
||||||
|
# date_str = dt_object.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
return date_str
|
||||||
|
|
||||||
def epoch_to_human_readable(epoch_timestamp, timezone='GMT'):
|
def epoch_to_human_readable(epoch_timestamp, timezone='GMT'):
|
||||||
if isinstance(epoch_timestamp, str):
|
if isinstance(epoch_timestamp, str):
|
||||||
return epoch_timestamp # Already converted
|
return epoch_timestamp # Already converted
|
||||||
|
Loading…
Reference in New Issue
Block a user