S|
Size: a a a
S|
S|
tg
from telegraph import upload
def upload_to_telegraph(file):
with open(file, 'rb') as f:
path = upload.upload_file(f, proxies)
return f'https://telegra.ph{path[0]}'
tg
S|
from telegraph import upload
def upload_to_telegraph(file):
with open(file, 'rb') as f:
path = upload.upload_file(f, proxies)
return f'https://telegra.ph{path[0]}'
G
G
S|
G
tg
from aiograph import Telegraph
telegraph = Telegraph()
async def _download_file(self) -> list:
# Функция принимает сообщение, вытягивает из него file_id, загружает его на хостинг, возвращает ссылку
await bot.send_chat_action(self.message.chat.id, action=ChatActions.UPLOAD_PHOTO)
file_info = await bot.get_file(self.message.photo[len(self.message.photo) - 1].file_id)
file_id: str = file_info.file_id
downloaded_file = await bot.download_file_by_id(file_id)
src: str = './tmp/' + file_info.file_path
async with aiofiles.open(src, 'wb') as new_file:
await new_file.write(downloaded_file.read())
file_url: str = (await telegraph.upload(src, full=True))[0]
await aiofiles.os.remove(src)
# await self.message.reply(file_url)
return [file_id, file_url]
S|
from aiograph import Telegraph
telegraph = Telegraph()
async def _download_file(self) -> list:
# Функция принимает сообщение, вытягивает из него file_id, загружает его на хостинг, возвращает ссылку
await bot.send_chat_action(self.message.chat.id, action=ChatActions.UPLOAD_PHOTO)
file_info = await bot.get_file(self.message.photo[len(self.message.photo) - 1].file_id)
file_id: str = file_info.file_id
downloaded_file = await bot.download_file_by_id(file_id)
src: str = './tmp/' + file_info.file_path
async with aiofiles.open(src, 'wb') as new_file:
await new_file.write(downloaded_file.read())
file_url: str = (await telegraph.upload(src, full=True))[0]
await aiofiles.os.remove(src)
# await self.message.reply(file_url)
return [file_id, file_url]
tg
S|
S|
tg
S|
G
from aiograph import Telegraph
telegraph = Telegraph()
async def _download_file(self) -> list:
# Функция принимает сообщение, вытягивает из него file_id, загружает его на хостинг, возвращает ссылку
await bot.send_chat_action(self.message.chat.id, action=ChatActions.UPLOAD_PHOTO)
file_info = await bot.get_file(self.message.photo[len(self.message.photo) - 1].file_id)
file_id: str = file_info.file_id
downloaded_file = await bot.download_file_by_id(file_id)
src: str = './tmp/' + file_info.file_path
async with aiofiles.open(src, 'wb') as new_file:
await new_file.write(downloaded_file.read())
file_url: str = (await telegraph.upload(src, full=True))[0]
await aiofiles.os.remove(src)
# await self.message.reply(file_url)
return [file_id, file_url]
from typing import Union
from aiograph import Telegraph
from aiogram.types import *
telegraph = Telegraph()
async def upload(file: Union[PhotoSize, Audio, Document, Video, Animation, Voice, VideoNote]):
return await telegraph.upload_from_url(await file.get_url())
ЮЧ
G
ЮЧ