Moved to aiohttp and aiofiles

This commit is contained in:
2023-03-02 22:38:48 +01:00
parent a913ba19c6
commit 4331af415e
3 changed files with 27 additions and 13 deletions

View File

@@ -1,9 +1,10 @@
from datetime import datetime
from os import makedirs, path
from shutil import copyfileobj, rmtree
from shutil import rmtree
from traceback import format_exc
from uuid import uuid4
from PIL import Image
import aiofiles
from classes.poster_client import PosterClient
@@ -35,7 +36,7 @@ async def send_content(app: PosterClient) -> None:
await app.send_message(app.owner, locale("api_queue_error", "message", locale=configGet("locale")))
return
response = await http_session.get(f'{configGet("address", "posting", "api")}/photos/{pic[0]}', headers={"Authorization": f"Bearer {token}"}, stream=True)
response = await http_session.get(f'{configGet("address", "posting", "api")}/photos/{pic[0]}', headers={"Authorization": f"Bearer {token}"})
if response.status != 200:
logWrite(locale("post_invalid_pic", "console", locale=configGet("locale")).format(response.status, str(response.json())))
@@ -48,8 +49,8 @@ async def send_content(app: PosterClient) -> None:
tmp_path = path.join(tmp_dir, pic[1])
with open(path.join(configGet("tmp", "locations"), tmp_path), 'wb') as out_file:
out_file.write(await response.read())
async with aiofiles.open(path.join(configGet("tmp", "locations"), tmp_path), 'wb') as out_file:
await out_file.write(await response.read())
logWrite(f'Candidate {pic[1]} ({pic[0]}) is {path.getsize(path.join(configGet("tmp", "locations"), tmp_path))} bytes big', debug=True)