Асинхронный постинг локальных фото в telegraph
У меня есть до 10 фотографий отправленных юзером, мне нужно асинхронно создать статью изагрузить иx с локальной машины на telegraph. Как? Спасибо
import asyncio
from telegraph import Telegraph
from html_telegraph_poster import upload_image
telegraph = Telegraph()
telegraph.create_account(short_name='Queen')
async def create_photo_albom(id_user:int, name:str, photo_albom:list):
html = f'<h4>Альбом пользователя {name}</h4><br>'
dirr = 'photo/'
for photo in photo_albom:
html+=f"<img src='{upload_image(dirr+photo)}'/><br>"
response = telegraph.create_page(
f'{id_user}',
html_content=html)
return ('http://telegra.ph/{}'.format(response['path']))
Ответы (1 шт):
Автор решения: Queen Ants
→ Ссылка
import asyncio
from aiograph import Telegraph
loop = asyncio.get_event_loop()
telegraph = Telegraph()
async def main():
await telegraph.create_account('aiograph-demo')
page = await telegraph.create_page('Demo', '<p><strong>Hello, world!</strong></p>')
print('Created page:', page.url)
if __name__ == '__main__':
try:
loop.run_until_complete(main())
except (KeyboardInterrupt, SystemExit):
pass
finally:
loop.run_until_complete(telegraph.close()) # Close the aiohttp.ClientSession