download files instead of passing by link
This commit is contained in:
parent
3bee7c0bc2
commit
8729994bf8
10
main.py
10
main.py
@ -1,7 +1,9 @@
|
||||
import asyncio
|
||||
import logging
|
||||
import os
|
||||
from io import BytesIO
|
||||
|
||||
import httpx
|
||||
import redis.asyncio as aioredis
|
||||
from aiogram import Bot, Dispatcher
|
||||
from aiogram.types import Message
|
||||
@ -41,16 +43,20 @@ async def check_updates():
|
||||
if post.file.url:
|
||||
try:
|
||||
logging.warning(post.file.url)
|
||||
async with httpx.AsyncClient() as client:
|
||||
io = BytesIO()
|
||||
file = io.write((await client.get(post.file.url)).content)
|
||||
file.name = f'file.{post.file.ext}'
|
||||
if post.file.ext == 'webm':
|
||||
await bot.send_video(int(os.environ['SEND_CHAT']),
|
||||
post.file.url,
|
||||
file,
|
||||
width=post.file.width,
|
||||
height=post.file.height,
|
||||
thumb=post.preview.url,
|
||||
caption=caption)
|
||||
else:
|
||||
await bot.send_photo(int(os.environ['SEND_CHAT']),
|
||||
post.file.url,
|
||||
file,
|
||||
caption=caption)
|
||||
await redis.sadd('e621:sent', post.id)
|
||||
except exceptions.TelegramAPIError as e:
|
||||
|
Loading…
Reference in New Issue
Block a user