File size: 746 Bytes
5979dfe
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import aiohttp
import asyncio
from io import BytesIO

async def photo_link(photo_bytes):
    form = aiohttp.FormData()
    form.add_field(
        name='file',
        value=photo_bytes,
    )
    async with aiohttp.ClientSession() as session:
        async with session.post('https://telegra.ph/upload', data=form) as response:
            img_src = await response.json()
            link = 'http://telegra.ph/' + img_src[0]["src"]
            return link

async def main():
    with open('Sertifikat.png', 'rb') as photo_file:  # Bunda tirnoqlarni olib tashlang
        photo_bytes = BytesIO(photo_file.read())
        link = await photo_link(photo_bytes)
        print(f"Rasm linki: {link}")

if __name__ == "__main__":
    asyncio.run(main())