Skip to content

Commit

Permalink
upgrade deps and fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Nov 20, 2023
1 parent d932cbd commit 55d8cc1
Show file tree
Hide file tree
Showing 5 changed files with 224 additions and 219 deletions.
11 changes: 2 additions & 9 deletions kleinanzeigen_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ def __init__(self) -> None:
self.categories:dict[str, str] = {}

self.file_log:logging.FileHandler | None = None
if is_frozen():
log_file_basename = os.path.splitext(os.path.basename(sys.executable))[0]
else:
log_file_basename = self.__module__
log_file_basename = is_frozen() and os.path.splitext(os.path.basename(sys.executable))[0] or self.__module__
self.log_file_path:str | None = abspath(f"{log_file_basename}.log")

self.command = "help"
Expand Down Expand Up @@ -870,11 +867,7 @@ def extract_ad_page_info(self, directory:str, id_:int) -> dict[str, Any]:
info:dict[str, Any] = {'active': True}

# extract basic info
if 's-anzeige' in self.webdriver.current_url:
o_type = 'OFFER'
else:
o_type = 'WANTED'
info['type'] = o_type
info['type'] = 'OFFER' if 's-anzeige' in self.webdriver.current_url else 'WANTED'
title:str = self.webdriver.find_element(By.CSS_SELECTOR, '#viewad-title').text
LOG.info('Extracting information from ad with title \"%s\"', title)
info['title'] = title
Expand Down
3 changes: 1 addition & 2 deletions kleinanzeigen_bot/selenium_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
from selenium.webdriver.remote.webdriver import WebDriver
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.expected_conditions import AnyDriver
from selenium.webdriver.support.ui import Select, WebDriverWait
import selenium_stealth
import webdriver_manager.core
Expand Down Expand Up @@ -244,7 +243,7 @@ def find_compatible_browser(self) -> tuple[str, ChromeType, str] | None: # -> [
LOG.warning("Installed browser could not be detected")
return None

def web_await(self, condition: Callable[[AnyDriver], T], timeout:float = 5, exception_on_timeout: Callable[[], Exception] | None = None) -> T:
def web_await(self, condition: Callable[[WebDriver], T], timeout:float = 5, exception_on_timeout: Callable[[], Exception] | None = None) -> T:
"""
Blocks/waits until the given condition is met.
Expand Down
5 changes: 1 addition & 4 deletions kleinanzeigen_bot/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,7 @@ def on_sigint(_sig:int, _frame:FrameType | None) -> None:


def pause(min_ms:int = 200, max_ms:int = 2000) -> None:
if max_ms <= min_ms:
duration = min_ms
else:
duration = secrets.randbelow(max_ms - min_ms) + min_ms
duration = max_ms <= min_ms and min_ms or secrets.randbelow(max_ms - min_ms) + min_ms
LOG.log(logging.INFO if duration > 1500 else logging.DEBUG, " ... pausing for %d ms ...", duration)
time.sleep(duration / 1000)

Expand Down
Loading

0 comments on commit 55d8cc1

Please sign in to comment.