Skip to content

Commit 8553f02

Browse files
committed
simplejson switch and decimal
1 parent db26c66 commit 8553f02

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

surftimer/ck_latestrecords.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,19 @@
22
from fastapi.responses import JSONResponse
33
from pydantic import BaseModel
44
from sql import selectQuery, insertQuery
5-
from globals import get_cache, set_cache
6-
import time, json
5+
from globals import get_cache, set_cache, default_serializer
6+
import time
7+
import simplejson as json
78
import surftimer.queries
9+
from decimal import Decimal
810

911
router = APIRouter()
1012

1113

1214
class LatestRec(BaseModel):
1315
steamid32: str
1416
name: str
15-
runtime: float
17+
runtime: Decimal
1618
mapname: str
1719

1820
# ck_latestrecords

surftimer/ck_playeroptions2.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
from sql import selectQuery, insertQuery
44
from globals import get_cache, set_cache
55
from pydantic import BaseModel
6-
import time, json, surftimer.queries
6+
import time, surftimer.queries
7+
import simplejson as json
78

89

910
router = APIRouter()
@@ -90,7 +91,7 @@ async def selectPlayerOptions(request: Request, response: Response, steamid32: s
9091
if cached_data is not None:
9192
print(f"[Redis] Loaded '{cache_key}' ({time.perf_counter() - tic:0.4f}s)")
9293
return JSONResponse(
93-
status_code=status.HTTP_200_OK, content=json.loads(cached_data)
94+
status_code=status.HTTP_200_OK, content=json.loads(cached_data, allow_nan=True)
9495
)
9596

9697
xquery = selectQuery(surftimer.queries.sql_selectPlayerOptions.format(steamid32))
@@ -99,7 +100,7 @@ async def selectPlayerOptions(request: Request, response: Response, steamid32: s
99100
xquery = xquery.pop()
100101
else:
101102
return JSONResponse(
102-
status_code=status.HTTP_404_NOT_FOUND, content=json.loads(cached_data)
103+
status_code=status.HTTP_404_NOT_FOUND, content=json.loads(cached_data, allow_nan=True)
103104
)
104105

105106
# Cache the data in Redis

0 commit comments

Comments
 (0)