Untitled
1 year ago in Python
def main():
"""Главная функция запуска бота."""
if not check_tokens():
exit()
bot = telegram.Bot(token=TELEGRAM_TOKEN)
current_timestamp = 0
previous_hw_info = {}
while True:
try:
response = get_api_answer(current_timestamp)
current_hw_info = check_response(response)[0]
if previous_hw_info == current_hw_info:
_logger.debug('Статус работы не изменился.')
if previous_hw_info:
_logger.debug('Изменился статус работы')
send_message(bot, parse_status(current_hw_info))
previous_hw_info = current_hw_info
current_timestamp = to_unix(current_hw_info.get('date_updated'))
except RequestExceptionError as error:
_logger.error(error)
current_error = f'Сбой в работе программы: {error}'
send_message(bot, current_error)
except SendMessageError as error:
_logger.error(error)
finally:
time.sleep(RETRY_PERIOD)