made HTTP request async
This commit is contained in:
parent
379f5dfb50
commit
71af05c3ba
@ -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)})
|
||||
|
||||
|
@ -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
|
Loading…
Reference in New Issue
Block a user