mirror of
https://github.com/Balshgit/mosgortrans.git
synced 2025-09-11 13:00:40 +03:00
ttl hash to 28 seconds
This commit is contained in:
parent
f9c4da89a9
commit
cd307e6403
@ -8,7 +8,11 @@ import wget
|
||||
from app.core.logger import logger
|
||||
from app.settings import BASE_DIR, GECKO_DRIVER_VERSION
|
||||
from selenium import webdriver
|
||||
from selenium.common.exceptions import NoSuchElementException, WebDriverException
|
||||
from selenium.common.exceptions import (
|
||||
NoSuchElementException,
|
||||
StaleElementReferenceException,
|
||||
WebDriverException,
|
||||
)
|
||||
from selenium.webdriver.firefox import options
|
||||
from selenium.webdriver.firefox.service import Service
|
||||
from selenium.webdriver.firefox.webdriver import RemoteWebDriver, WebDriver
|
||||
@ -69,9 +73,6 @@ def parse_site(url: str, message: str, driver: RemoteWebDriver | None = None) ->
|
||||
bus_300_arrival = element.find_element(
|
||||
by='class name', value='masstransit-prognoses-view__title-text'
|
||||
)
|
||||
except NoSuchElementException:
|
||||
pass
|
||||
try:
|
||||
bus_t19 = element.find_element(
|
||||
by='css selector', value='[aria-label="т19"]'
|
||||
)
|
||||
@ -80,6 +81,8 @@ def parse_site(url: str, message: str, driver: RemoteWebDriver | None = None) ->
|
||||
)
|
||||
except NoSuchElementException:
|
||||
pass
|
||||
except StaleElementReferenceException:
|
||||
pass
|
||||
answer = f'{message}\n\n'
|
||||
if not all([bus_300, bus_t19]) or not all([bus_300_arrival, bus_t19_arrival]):
|
||||
return 'Автобусов 300 или Т19 не найдено. \n\nСмотри на карте :)'
|
||||
@ -97,6 +100,7 @@ def get_ttl_hash(seconds: int = 28) -> int:
|
||||
|
||||
@lru_cache
|
||||
def get_driver(ttl_hash: int | None = None) -> RemoteWebDriver:
|
||||
del ttl_hash
|
||||
opt = options.Options()
|
||||
opt.headless = True
|
||||
driver = RemoteWebDriver(
|
||||
|
Loading…
x
Reference in New Issue
Block a user