diff --git a/src/beebot.py b/src/beebot.py index 8310ebb..317fb22 100644 --- a/src/beebot.py +++ b/src/beebot.py @@ -8,7 +8,7 @@ import subprocess from sqlite3 import Connection from typing import Optional, Callable -import requests +import aiohttp import telegram.constants from bs4 import BeautifulSoup from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton @@ -371,12 +371,16 @@ class BeeBot: headers = { "User-Agent": "BeeBot 1.0" } - res = requests.get(url, headers=headers) + async with aiohttp.ClientSession() as session: + async with session.get(url, headers=headers) as response: + if response.status != 200: + return [] - if res.status_code != 200: - return [] + content = await response.read() + return self.parse_menu(content) - bs = BeautifulSoup(res.content, features="lxml") + def parse_menu(self, content: bytes) -> list: + bs = BeautifulSoup(content, features="lxml") table = bs.find("table", {"id": "menuTable"}) lines = table.find("tbody").findAll("tr", {"data-restoid": str(self.RESTO_ID)}) diff --git a/src/requirements.txt b/src/requirements.txt index 225b5d4..32e3d8c 100644 --- a/src/requirements.txt +++ b/src/requirements.txt @@ -1,4 +1,5 @@ requests==2.25.1 +aiohttp==3.10.5 beautifulsoup4==4.10.0 lxml==4.8.0 python-telegram-bot==21.5 \ No newline at end of file