fix tag count limit
This commit is contained in:
parent
547132d5d6
commit
3bee7c0bc2
63
main.py
63
main.py
@ -23,37 +23,38 @@ dp = Dispatcher(bot)
|
|||||||
async def check_updates():
|
async def check_updates():
|
||||||
async with redis.lock('e621:update'):
|
async with redis.lock('e621:update'):
|
||||||
tag_list = [t.decode() for t in await redis.smembers('e621:subs')]
|
tag_list = [t.decode() for t in await redis.smembers('e621:subs')]
|
||||||
tags = ' '.join(f'~{tag}' for tag in tag_list)
|
for tl_idx in range(0, len(tag_list), 40):
|
||||||
posts = await e621.get_posts(tags)
|
tags = ' '.join(f'~{tag}' for tag in tag_list[tl_idx: tl_idx + 40])
|
||||||
if not posts:
|
posts = await e621.get_posts(tags)
|
||||||
return
|
if not posts:
|
||||||
already_sent = await redis.smismember('e621:sent', [p.id for p in posts])
|
return
|
||||||
for i in range(len(posts)):
|
already_sent = await redis.smismember('e621:sent', [p.id for p in posts])
|
||||||
if already_sent[i]:
|
for i in range(len(posts)):
|
||||||
continue
|
if already_sent[i]:
|
||||||
post = posts[i]
|
continue
|
||||||
monitored_tags = set(post.tags.flatten()) & set(tag_list)
|
post = posts[i]
|
||||||
caption = f'Monitored tags: {" ".join(monitored_tags)}\n' \
|
monitored_tags = set(post.tags.flatten()) & set(tag_list)
|
||||||
f'Artist: {" ".join(post.tags.artist)}\n' \
|
caption = f'Monitored tags: {" ".join(monitored_tags)}\n' \
|
||||||
f'Character: {" ".join(post.tags.character)}\n\n' \
|
f'Artist: {" ".join(post.tags.artist)}\n' \
|
||||||
f'https://e621.net/posts/{post.id}'
|
f'Character: {" ".join(post.tags.character)}\n\n' \
|
||||||
if post.file.url:
|
f'https://e621.net/posts/{post.id}'
|
||||||
try:
|
if post.file.url:
|
||||||
logging.warning(post.file.url)
|
try:
|
||||||
if post.file.ext == 'webm':
|
logging.warning(post.file.url)
|
||||||
await bot.send_video(int(os.environ['SEND_CHAT']),
|
if post.file.ext == 'webm':
|
||||||
post.file.url,
|
await bot.send_video(int(os.environ['SEND_CHAT']),
|
||||||
width=post.file.width,
|
post.file.url,
|
||||||
height=post.file.height,
|
width=post.file.width,
|
||||||
thumb=post.preview.url,
|
height=post.file.height,
|
||||||
caption=caption)
|
thumb=post.preview.url,
|
||||||
else:
|
caption=caption)
|
||||||
await bot.send_photo(int(os.environ['SEND_CHAT']),
|
else:
|
||||||
post.file.url,
|
await bot.send_photo(int(os.environ['SEND_CHAT']),
|
||||||
caption=caption)
|
post.file.url,
|
||||||
await redis.sadd('e621:sent', post.id)
|
caption=caption)
|
||||||
except exceptions.TelegramAPIError as e:
|
await redis.sadd('e621:sent', post.id)
|
||||||
logging.exception(e)
|
except exceptions.TelegramAPIError as e:
|
||||||
|
logging.exception(e)
|
||||||
|
|
||||||
|
|
||||||
@dp.message_handler(commands=['add'])
|
@dp.message_handler(commands=['add'])
|
||||||
|
Loading…
Reference in New Issue
Block a user