Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to v4 #62

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open

Update to v4 #62

wants to merge 15 commits into from

Conversation

alcortazzo
Copy link
Owner

@alcortazzo alcortazzo commented Aug 12, 2023

  • Implemented the ability to run multiple bots with a single script
  • Made bot compatible with aiogram v3+

@Ololoshka8
Copy link

Добрый день. Возможно ли исправить:
AttributeError: module 'aiogram.types' has no attribute 'MediaGroup'.
Плюс еще поправить бы parse_mode=types.ParseMode.HTML. Не работает так. Работает вот так: parse_mode="HTML"

@alcortazzo
Copy link
Owner Author

@Ololoshka8

Беглым взглядом глянул - types.ParseMode.HTML - это и есть "HTML" (источник).

Какая версия у вас Python и aiogram?

@Ololoshka8
Copy link

@Ololoshka8

Беглым взглядом глянул - types.ParseMode.HTML - это и есть "HTML" (источник).

Какая версия у вас Python и aiogram?

Я запускаю через докер. Git Clone и docker-compose. Ну и подредактировал конфиг файл (поставил свои ID куда нужно)

  1. Сначала была такая ошибка: ImportError: cannot import name 'executor' from 'aiogram.utils' (/root/.local/lib/python3.10/site-packages/aiogram/utils/init.py). Ее исправил - нашел ветку dev4. Там этой проблемы нет.
  2. Потом такая ошибка - AttributeError: module 'aiogram.types' has no attribute 'ParseMode'. Ее тоже решил. Поменял как написал выше: parse_mode="HTML". Так заработало.
  3. Потом, после постинга с фотками - AttributeError: module 'aiogram.types' has no attribute 'MediaGroup'. Точнее там 1 видео было.
  4. а потом вообще вот такая ошибка - https://pastebin.com/XF0N8rLF

@Ololoshka8
Copy link

Добрый день. Я рассматриваю сейчас форк - https://github.com/Atronar/alcortazzo-vktgbot. Не знаю куда там написать. Напишу сюда. Ситуация такая: я прописываю в файл last_known_id.txt номер последнего сообщения в группе. Далее в группе еще появляются, например, 5 постов новых. Скрипт кидает их в телегу. Все как нужно. Просто супер. Но! если я перезапускаю контейнер, то он поновой этиже 5 новых сообщений кидает. Опять начинает с того же номера, которого я прописывал в файл. Хотя я смотрю. что вроде как реализовано, чтобы записывал новый номер сообщения в файл и начинал с него. Но у меня почему то не отрабатывает данный функционал (( Помогите!

@alcortazzo
Copy link
Owner Author

@Ololoshka8

Спасибо за багрепорт. Сейчас проверил - действительно, aiogram на новых версиях выдает ошибку.
Залочил версию в requirements.txt, сейчас все ок.

Что касается проблемы с файлом last_known_id.txt - у меня таких проблем не наблюдается и не наблюдалось. Подозреваю, что проблема в изменениях в форке.

Copy link

@ilystsov ilystsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use for instead of while; use else instead of if in loop body for consistency and readability

Comment on lines +44 to +45
if num_tries > 5:
logger.error(f"{config_name} - Post was not sent to Telegram. Too many tries.")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if num_tries > 5:
logger.error(f"{config_name} - Post was not sent to Telegram. Too many tries.")
else:
logger.error(f"{config_name} - Post was not sent to Telegram. Too many tries.")

Comment on lines +23 to +25
num_tries = 1
while num_tries <= 5:
num_tries += 1
Copy link

@ilystsov ilystsov Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
num_tries = 1
while num_tries <= 5:
num_tries += 1
MAX_TRIES = 5
for num_tries in range(1, MAX_TRIES + 1):

Copy link

@ilystsov ilystsov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use constants instead of magic numbers where possible

photos (list): List of photos.
docs (list): List of documents.
config_name (str): Name of config.
"""

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""
"""
RETRY_DELAY = 10
BAD_REQUEST_DELAY = 60

Comment on lines +38 to +40
f"{config_name} - Flood limit is exceeded. Sleep {ex.retry_after + 10} seconds. Try: {num_tries - 1}."
)
await asyncio.sleep(ex.retry_after + 10)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
f"{config_name} - Flood limit is exceeded. Sleep {ex.retry_after + 10} seconds. Try: {num_tries - 1}."
)
await asyncio.sleep(ex.retry_after + 10)
f"{config_name} - Flood limit is exceeded. Sleep {ex.retry_after + RETRY_DELAY} seconds. Try: {num_tries - 1}."
)
await asyncio.sleep(ex.retry_after + RETRY_DELAY)

Comment on lines +42 to +43
logger.warning(f"{config_name} - Bad request. Wait 60 seconds. Try: {num_tries}. {ex}")
await asyncio.sleep(60)
Copy link

@ilystsov ilystsov Oct 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
logger.warning(f"{config_name} - Bad request. Wait 60 seconds. Try: {num_tries}. {ex}")
await asyncio.sleep(60)
logger.warning(f"{config_name} - Bad request. Wait {BAD_REQUEST_DELAY} seconds. Try: {num_tries}. {ex}")
await asyncio.sleep(BAD_REQUEST_DELAY)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants