reconnect after disconnect and terminate on CTRL+C
All checks were successful
ci / docker (push) Successful in 6m33s
Python formatting PEP8 / Python-PEP8 (push) Successful in 15s

This commit is contained in:
Finn Christiansen 2024-07-04 21:55:10 +02:00
parent ffc1c5814e
commit 04757a3f6a

View file

@ -1,9 +1,12 @@
import simplematrixbotlib as botlib
import requests
import os
import sys
import logging
import smtplib
import datetime
import time
from aiohttp.client_exceptions import ServerDisconnectedError
from email.mime.text import MIMEText
from dotenv import load_dotenv
@ -110,4 +113,12 @@ The link will be valid for 7 days.""".format(os.getenv("REGISTRATION_URL") + res
server.quit()
bot.run()
while True:
try:
bot.run()
except ServerDisconnectedError:
time.sleep(5)
print("connection lost, reconnecting in 5 seconds...")
except KeyboardInterrupt:
print("exiting...")
sys.exit(0)