update captions
This commit is contained in:
		
							
								
								
									
										27
									
								
								main.py
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								main.py
									
									
									
									
									
								
							@@ -7,7 +7,7 @@ from PIL import Image
 | 
				
			|||||||
import httpx
 | 
					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, ParseMode
 | 
				
			||||||
from aiogram.utils import executor, exceptions
 | 
					from aiogram.utils import executor, exceptions
 | 
				
			||||||
import dotenv
 | 
					import dotenv
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -41,10 +41,16 @@ async def check_updates():
 | 
				
			|||||||
                    continue
 | 
					                    continue
 | 
				
			||||||
                post = posts[i]
 | 
					                post = posts[i]
 | 
				
			||||||
                monitored_tags = set(post.tags.flatten()) & set(tag_list)
 | 
					                monitored_tags = set(post.tags.flatten()) & set(tag_list)
 | 
				
			||||||
                caption = f'Monitored tags: {" ".join(monitored_tags)}\n' \
 | 
					                artist_tags = post.tags.artist
 | 
				
			||||||
                          f'Artist: {" ".join(post.tags.artist)}\n' \
 | 
					                character_tags = post.tags.character
 | 
				
			||||||
                          f'Character: {" ".join(post.tags.character)}\n\n' \
 | 
					                copyright_tags = post.tags.copyright
 | 
				
			||||||
                          f'https://e621.net/posts/{post.id}'
 | 
					                caption = '\n'.join(l for l in [
 | 
				
			||||||
 | 
					                    f'Monitored tags: <b>{" ".join(monitored_tags)}</b>',
 | 
				
			||||||
 | 
					                    artist_tags and f'Artist: <b>{" ".join(artist_tags)}</b>',
 | 
				
			||||||
 | 
					                    character_tags and f'Character: <b>{", ".join(character_tags)}</b>',
 | 
				
			||||||
 | 
					                    copyright_tags and f'Copyright: <b>{", ".join(copyright_tags)}</b>',
 | 
				
			||||||
 | 
					                    f'\nhttps://e621.net/posts/{post.id}'
 | 
				
			||||||
 | 
					                ] if l)
 | 
				
			||||||
                if post.file.url:
 | 
					                if post.file.url:
 | 
				
			||||||
                    try:
 | 
					                    try:
 | 
				
			||||||
                        logging.warning(post.file.url)
 | 
					                        logging.warning(post.file.url)
 | 
				
			||||||
@@ -59,14 +65,16 @@ async def check_updates():
 | 
				
			|||||||
                                                     width=post.file.width,
 | 
					                                                     width=post.file.width,
 | 
				
			||||||
                                                     height=post.file.height,
 | 
					                                                     height=post.file.height,
 | 
				
			||||||
                                                     thumb=post.preview.url,
 | 
					                                                     thumb=post.preview.url,
 | 
				
			||||||
                                                     caption=caption)
 | 
					                                                     caption=caption,
 | 
				
			||||||
 | 
					                                                     parse_mode=ParseMode.HTML)
 | 
				
			||||||
                            elif post.file.ext == 'gif':
 | 
					                            elif post.file.ext == 'gif':
 | 
				
			||||||
                                await bot.send_animation(int(os.environ['SEND_CHAT']),
 | 
					                                await bot.send_animation(int(os.environ['SEND_CHAT']),
 | 
				
			||||||
                                                         file,
 | 
					                                                         file,
 | 
				
			||||||
                                                         width=post.file.width,
 | 
					                                                         width=post.file.width,
 | 
				
			||||||
                                                         height=post.file.height,
 | 
					                                                         height=post.file.height,
 | 
				
			||||||
                                                         thumb=post.preview.url,
 | 
					                                                         thumb=post.preview.url,
 | 
				
			||||||
                                                         caption=caption)
 | 
					                                                         caption=caption,
 | 
				
			||||||
 | 
					                                                     parse_mode=ParseMode.HTML)
 | 
				
			||||||
                            elif post.file.ext in ('png', 'jpg'):
 | 
					                            elif post.file.ext in ('png', 'jpg'):
 | 
				
			||||||
                                if post.file.size > 10000000:
 | 
					                                if post.file.size > 10000000:
 | 
				
			||||||
                                    logging.warning('compressing')
 | 
					                                    logging.warning('compressing')
 | 
				
			||||||
@@ -84,7 +92,8 @@ async def check_updates():
 | 
				
			|||||||
                                    file.name = 'file.jpg'
 | 
					                                    file.name = 'file.jpg'
 | 
				
			||||||
                                await bot.send_photo(int(os.environ['SEND_CHAT']),
 | 
					                                await bot.send_photo(int(os.environ['SEND_CHAT']),
 | 
				
			||||||
                                                     file,
 | 
					                                                     file,
 | 
				
			||||||
                                                     caption=caption)
 | 
					                                                     caption=caption,
 | 
				
			||||||
 | 
					                                                     parse_mode=ParseMode.HTML)
 | 
				
			||||||
                        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)
 | 
				
			||||||
@@ -114,7 +123,7 @@ async def del_tag(msg: Message):
 | 
				
			|||||||
        await msg.reply('Tag not found')
 | 
					        await msg.reply('Tag not found')
 | 
				
			||||||
        return
 | 
					        return
 | 
				
			||||||
    await redis.srem('e621:subs', args)
 | 
					    await redis.srem('e621:subs', args)
 | 
				
			||||||
    await msg.reply(f'Tag {msg} removed')
 | 
					    await msg.reply(f'Tag {args} removed')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@dp.message_handler(commands=['list'])
 | 
					@dp.message_handler(commands=['list'])
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user