Compare commits

...

2 Commits

Author SHA1 Message Date
daniel156161 2d7a2505d4 create payload of json string and then save it
Build and Push Docker Container / build-and-push (push) Successful in 1m33s
2026-04-03 14:31:15 +02:00
daniel156161 a82eaaaec5 allow sync and async function calls 2026-04-03 14:10:38 +02:00
2 changed files with 26 additions and 22 deletions
+8 -2
View File
@@ -1,6 +1,7 @@
import aiofiles.os
import aiofiles
import os
import inspect
async def read_file(path: str, callback=None):
if not await aiofiles.os.path.exists(path):
@@ -8,7 +9,10 @@ async def read_file(path: str, callback=None):
async with aiofiles.open(path, "r") as f:
if callback:
return await callback(f)
result = callback(f)
if inspect.isawaitable(result):
return await result
return result
return await f.read()
@@ -19,6 +23,8 @@ async def save_file(path: str, data, callback=None, *args, **kwargs):
async with aiofiles.open(path, "w") as f:
if callback:
await callback(data, f, *args, **kwargs)
result = callback(data, f, *args, **kwargs)
if inspect.isawaitable(result):
await result
else:
await f.write(data)
+4 -6
View File
@@ -153,7 +153,7 @@ class LocalStorage:
True if game_board.winner_snake_names and "me" in game_board.winner_snake_names else False
)
await save_file(save_file_path, {
payload = {
"winner": game_board.winner_snake_names,
"game": {
"url": game_board.url,
@@ -169,11 +169,9 @@ class LocalStorage:
"calculations": game_board.snake_class.get_history(),
},
"dataset": dataset,
},
callback=json.dump,
indent=2,
ensure_ascii=False,
)
}
await save_file(save_file_path, json.dumps(payload, indent=2, ensure_ascii=False))
def cleanup(self):
pass