made HTTP request async
This commit is contained in:
parent
379f5dfb50
commit
71af05c3ba
@ -8,7 +8,7 @@ import subprocess
|
|||||||
from sqlite3 import Connection
|
from sqlite3 import Connection
|
||||||
from typing import Optional, Callable
|
from typing import Optional, Callable
|
||||||
|
|
||||||
import requests
|
import aiohttp
|
||||||
import telegram.constants
|
import telegram.constants
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
|
from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton
|
||||||
@ -371,12 +371,16 @@ class BeeBot:
|
|||||||
headers = {
|
headers = {
|
||||||
"User-Agent": "BeeBot 1.0"
|
"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:
|
content = await response.read()
|
||||||
return []
|
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"})
|
table = bs.find("table", {"id": "menuTable"})
|
||||||
lines = table.find("tbody").findAll("tr", {"data-restoid": str(self.RESTO_ID)})
|
lines = table.find("tbody").findAll("tr", {"data-restoid": str(self.RESTO_ID)})
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
requests==2.25.1
|
requests==2.25.1
|
||||||
|
aiohttp==3.10.5
|
||||||
beautifulsoup4==4.10.0
|
beautifulsoup4==4.10.0
|
||||||
lxml==4.8.0
|
lxml==4.8.0
|
||||||
python-telegram-bot==21.5
|
python-telegram-bot==21.5
|
Loading…
Reference in New Issue
Block a user