The question is as to why it does not write certain logs to the file, errors are not shown.
Bot for tg on aiogram.
logs.py:
import aiofiles
import asyncio
async def writelog(user_id: int, log: str):
return
async with aiofiles.open('assets/recently.txt', mode='w') as f:
await f.write(f'{user_id}:{log}\n')
async def readlogs():
return ''
async with aiofiles.open('assets/recently.txt', mode='r') as f:
text = await f.read()
return text
The code for writing a log to a file from script:
await writelog(message.from_user.id, 'turn off notificationsđź””')
help with the code, please🤍
>Solution :
You are returning from the functions, that’s why it is not working.
Change the code to this
import aiofiles
import asyncio
async def writelog(user_id: int, log: str):
async with aiofiles.open('assets/recently.txt', mode='w') as f:
await f.write(f'{user_id}:{log}\n')
async def readlogs():
async with aiofiles.open('assets/recently.txt', mode='r') as f:
text = await f.read()
return text
If you don’t have complexity in your code and if you are calling the functions in a right manner, then this must work.