made HTTP request async
This commit is contained in:
		| @@ -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 res.status_code != 200: |                 if response.status != 200: | ||||||
|                     return [] |                     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"}) |         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 | ||||||
		Reference in New Issue
	
	Block a user