22import asyncio
33import json
44import time
5+ from datetime import datetime , timezone
56from typing import Any , cast
67
78import redis .asyncio as aioredis
1617redis : "aioredis.Redis"
1718
1819
20+ def unix_to_iso (timestamp : int ) -> str :
21+ """Convert Unix timestamp to ISO 8601 format string."""
22+ return datetime .fromtimestamp (timestamp , tz = timezone .utc ).isoformat ()
23+
24+
25+ def convert_timestamps_to_iso (data : list [dict ]) -> list [dict ]:
26+ """Convert Unix timestamp fields to ISO format in a list of dictionaries."""
27+ for item in data :
28+ # Convert score_time (for first places)
29+ if "score_time" in item and isinstance (item ["score_time" ], int ):
30+ item ["score_time" ] = unix_to_iso (item ["score_time" ])
31+ # Convert time (for high PP plays)
32+ if "time" in item and isinstance (item ["time" ], int ):
33+ item ["time" ] = unix_to_iso (item ["time" ])
34+ return data
35+
36+
1937async def connect () -> None :
2038 await db .connect (
2139 {
@@ -407,7 +425,8 @@ async def update_homepage_cache() -> None:
407425 f"""
408426 SELECT sf.scoreid, sf.userid, u.username, u.country,
409427 b.song_name, b.beatmap_id, b.beatmapset_id,
410- ROUND(s.pp) as pp, s.time as score_time
428+ ROUND(s.pp) as pp, s.time as score_time,
429+ s.mods, s.accuracy
411430 FROM scores_first sf
412431 INNER JOIN users u ON u.id = sf.userid
413432 INNER JOIN beatmaps b ON b.beatmap_md5 = sf.beatmap_md5
@@ -418,6 +437,8 @@ async def update_homepage_cache() -> None:
418437 """ ,
419438 (rx , play_mode ),
420439 )
440+ # Convert Unix timestamps to ISO format
441+ first_places = convert_timestamps_to_iso (first_places )
421442 await redis .set (
422443 f"akatsuki:first_places:{ combined_mode } " ,
423444 json .dumps (first_places , default = str ),
@@ -428,7 +449,8 @@ async def update_homepage_cache() -> None:
428449 f"""
429450 SELECT s.id, s.userid, ROUND(s.pp) as pp, s.time,
430451 u.username, u.country,
431- b.song_name, b.beatmap_id, b.beatmapset_id
452+ b.song_name, b.beatmap_id, b.beatmapset_id,
453+ s.mods, s.accuracy
432454 FROM { scores_table } s
433455 INNER JOIN users u ON u.id = s.userid
434456 INNER JOIN beatmaps b ON b.beatmap_md5 = s.beatmap_md5
@@ -440,6 +462,8 @@ async def update_homepage_cache() -> None:
440462 """ ,
441463 (pp_threshold , play_mode ),
442464 )
465+ # Convert Unix timestamps to ISO format
466+ high_pp = convert_timestamps_to_iso (high_pp )
443467 await redis .set (
444468 f"akatsuki:high_pp:{ combined_mode } " ,
445469 json .dumps (high_pp , default = str ),
0 commit comments