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