diff --git a/main.py b/main.py index 7486b4e..cb7bb99 100644 --- a/main.py +++ b/main.py @@ -152,9 +152,21 @@ async def getgameinfo(request: Request, oldGameId: int = 0, name: str = ""): @app.get("/getgameprice") -async def getgameprice(request: Request, oldGameId: int): +async def getgameprice(request: Request, oldGameId: int, nums: int = 0): db = request.app.state.mongo - gameprice = db["gameprice"].find_one({"oldGameId": oldGameId}, {"_id": 0}) + if nums == 0: + gameprice = db["gameprice"].find_one({"oldGameId": oldGameId}, + {"_id": 0}) + else: + gameprice = db["gameprice"].find_one({"oldGameId": oldGameId}, + {"_id": 0}) + price = gameprice.get('prices', []) + if price: + gameprice['prices'] = price[:nums] + else: + logger.error(f"get price with {oldGameId} failed\n {gameprice}") + gameprice['prices'] = [] + logger.info(f"get gameprice with {oldGameId} !") return JSONResponse( status_code=starlette.status.HTTP_200_OK,