|
|
|
@ -25,7 +25,7 @@ from aiogram.types import Message, InlineKeyboardMarkup, InlineKeyboardButton, B
|
|
|
|
|
CallbackQuery
|
|
|
|
|
import dotenv
|
|
|
|
|
|
|
|
|
|
from e621 import E621, E621Post
|
|
|
|
|
from e621 import E621, E621Post, E621PostFile
|
|
|
|
|
|
|
|
|
|
dotenv.load_dotenv('.env')
|
|
|
|
|
|
|
|
|
@ -43,6 +43,10 @@ def format_tags(tags: Iterable[str]):
|
|
|
|
|
return ' '.join(f'#{tag}' for tag in tags) or 'None'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def recover_url(file: E621PostFile):
|
|
|
|
|
return f'https://static1.e621.net/data/{file.md5[:2]}/{file.md5[:2:4]}/{file.md5}.{file.ext}'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
async def send_post(post: E621Post, tag_list: List[str]):
|
|
|
|
|
try:
|
|
|
|
|
logging.warning(f'Sending post #{post.id}')
|
|
|
|
@ -58,7 +62,8 @@ async def send_post(post: E621Post, tag_list: List[str]):
|
|
|
|
|
copyright_tags and f'Copyright: <b>{format_tags(copyright_tags)}</b>',
|
|
|
|
|
f'\nhttps://e621.net/posts/{post.id}'
|
|
|
|
|
] if l)
|
|
|
|
|
if post.file.url:
|
|
|
|
|
if not post.file.url:
|
|
|
|
|
post.file.url = recover_url(post.file)
|
|
|
|
|
try:
|
|
|
|
|
logging.warning(post.file.url)
|
|
|
|
|
async with httpx.AsyncClient() as client:
|
|
|
|
@ -118,8 +123,6 @@ async def send_post(post: E621Post, tag_list: List[str]):
|
|
|
|
|
await redis.sadd('e621:sent', post.id)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.exception(e)
|
|
|
|
|
else:
|
|
|
|
|
logging.warning('Not sending because url is None', post.file)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
logging.exception(e)
|
|
|
|
|
|
|
|
|
|