ClientConnectorError fix
This commit is contained in:
parent
c8cf8bf804
commit
55b3f830bb
1 changed files with 14 additions and 28 deletions
42
main.py
42
main.py
|
@ -7,7 +7,6 @@ import datetime as dt
|
||||||
import locale
|
import locale
|
||||||
from time import sleep
|
from time import sleep
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
import aiohttp
|
|
||||||
|
|
||||||
# Modify the links and data below:
|
# Modify the links and data below:
|
||||||
DEADLINES_URL = "https://m3104.nawinds.dev/DEADLINES.json"
|
DEADLINES_URL = "https://m3104.nawinds.dev/DEADLINES.json"
|
||||||
|
@ -20,7 +19,6 @@ TOKEN = os.getenv("TOKEN")
|
||||||
MAIN_GROUP_ID = int(os.getenv("MAIN_GROUP_ID"))
|
MAIN_GROUP_ID = int(os.getenv("MAIN_GROUP_ID"))
|
||||||
|
|
||||||
logging.basicConfig(level=logging.INFO)
|
logging.basicConfig(level=logging.INFO)
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
bot = Bot(TOKEN)
|
bot = Bot(TOKEN)
|
||||||
|
|
||||||
|
@ -146,34 +144,22 @@ async def get_message_text() -> str:
|
||||||
return text
|
return text
|
||||||
|
|
||||||
async def send_deadlines(chat_id: int) -> None:
|
async def send_deadlines(chat_id: int) -> None:
|
||||||
retries = 20
|
text = await get_message_text()
|
||||||
for attempt in range(retries):
|
msg = await bot.send_message(chat_id, text, parse_mode="HTML", disable_web_page_preview=True)
|
||||||
try:
|
started_updating = dt.datetime.now()
|
||||||
text = await get_message_text()
|
while dt.datetime.now() - started_updating < dt.timedelta(days=1):
|
||||||
msg = await bot.send_message(chat_id, text, parse_mode="HTML", disable_web_page_preview=True)
|
await asyncio.sleep(60)
|
||||||
started_updating = dt.datetime.now()
|
new_text = await get_message_text()
|
||||||
while dt.datetime.now() - started_updating < dt.timedelta(days=1):
|
if text != new_text and new_text != "":
|
||||||
await asyncio.sleep(60)
|
await msg.edit_text(new_text, parse_mode="HTML", disable_web_page_preview=True)
|
||||||
new_text = await get_message_text()
|
text = new_text
|
||||||
if text != new_text and new_text != "":
|
await msg.delete()
|
||||||
await msg.edit_text(new_text, parse_mode="HTML", disable_web_page_preview=True)
|
|
||||||
text = new_text
|
|
||||||
await msg.delete()
|
|
||||||
break
|
|
||||||
except aiohttp.ClientConnectorError as e:
|
|
||||||
logger.error(f"Attempt {attempt + 1} failed: {e}")
|
|
||||||
if attempt < retries - 1:
|
|
||||||
await asyncio.sleep(2 ** attempt) # Exponential backoff
|
|
||||||
else:
|
|
||||||
raise
|
|
||||||
|
|
||||||
async def main():
|
async def main():
|
||||||
try:
|
await send_deadlines(MAIN_GROUP_ID)
|
||||||
await send_deadlines(MAIN_GROUP_ID)
|
await bot.session.close()
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"An error occurred: {e}")
|
|
||||||
finally:
|
|
||||||
await bot.session.close()
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
asyncio.run(main())
|
asyncio.run(main())
|
Loading…
Add table
Add a link
Reference in a new issue