made HTTP request async

This commit is contained in:
Louis Heredero 2024-09-14 15:43:01 +02:00
parent 379f5dfb50
commit 71af05c3ba
Signed by: HEL
GPG Key ID: 8D83DE470F8544E7
2 changed files with 10 additions and 5 deletions

View File

@ -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)
if res.status_code != 200:
async with aiohttp.ClientSession() as session:
async with session.get(url, headers=headers) as response:
if response.status != 200:
return []
bs = BeautifulSoup(res.content, features="lxml")
content = await response.read()
return self.parse_menu(content)
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)})

View File

@ -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