mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2025-09-11 13:00:40 +03:00
run in executor
This commit is contained in:
parent
be00798312
commit
c5ed964486
@ -17,7 +17,6 @@ download_gecko_driver()
|
||||
driver = configure_firefox_driver()
|
||||
|
||||
executor = ThreadPoolExecutor(5)
|
||||
loop = asyncio.get_running_loop()
|
||||
|
||||
stations_cb = CallbackData('station', 'direction')
|
||||
|
||||
@ -50,6 +49,7 @@ async def home_office(
|
||||
)
|
||||
message = 'Остановка Б. Академическая ул, д. 15'
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
text = await loop.run_in_executor(executor, parse_site, driver, url, message)
|
||||
|
||||
# text = parse_site(
|
||||
|
@ -1,3 +1,4 @@
|
||||
import asyncio
|
||||
import os
|
||||
import tarfile
|
||||
import time
|
||||
@ -44,7 +45,7 @@ def configure_firefox_driver(private_window: bool = False) -> WebDriver:
|
||||
return firefox_driver
|
||||
|
||||
|
||||
def parse_site(driver: WebDriver, url: str, message: str) -> str:
|
||||
async def parse_site(driver: WebDriver, url: str, message: str) -> str:
|
||||
driver.get(url)
|
||||
time.sleep(4)
|
||||
elements = driver.find_elements(
|
||||
@ -80,4 +81,5 @@ def parse_site(driver: WebDriver, url: str, message: str) -> str:
|
||||
answer += f'Автобус {bus_300.text} - {bus_300_arrival.text}\n'
|
||||
if bus_t19 and bus_t19_arrival:
|
||||
answer += f'Автобус {bus_t19.text} - {bus_t19_arrival.text}'
|
||||
await asyncio.sleep(30)
|
||||
return answer
|
||||
|
Loading…
x
Reference in New Issue
Block a user