Skip to content

Commit

Permalink
feat: remove default prefix/suffix text from downloaded ads
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Nov 21, 2024
1 parent 5086721 commit 6a315c9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/kleinanzeigen_bot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,7 @@ async def download_ads(self) -> None:
This downloads either all, only unsaved (new), or specific ads given by ID.
"""

ad_extractor = extract.AdExtractor(self.browser)
ad_extractor = extract.AdExtractor(self.browser, self.config)

# use relevant download routine
if self.ads_selector in {'all', 'new'}: # explore ads overview for these two modes
Expand Down
8 changes: 5 additions & 3 deletions src/kleinanzeigen_bot/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class AdExtractor(WebScrapingMixin):
Wrapper class for ad extraction that uses an active bot´s browser session to extract specific elements from an ad page.
"""

def __init__(self, browser:Browser):
def __init__(self, browser:Browser, config:dict[str, Any]):
super().__init__()
self.browser = browser
self.config = config

async def download_ad(self, ad_id:int) -> None:
"""
Expand Down Expand Up @@ -230,8 +231,9 @@ async def _extract_ad_page_info(self, directory:str, ad_id:int) -> dict[str, Any
LOG.info('Extracting information from ad with title \"%s\"', title)
info['title'] = title

descr:str = await self.web_text(By.ID, 'viewad-description-text')
info['description'] = descr
info['description'] = (await self.web_text(By.ID, 'viewad-description-text')).strip() \
.removeprefix((self.config["ad_defaults"]["description"]["prefix"] or "").strip()) \
.removesuffix((self.config["ad_defaults"]["description"]["suffix"] or "").strip())

# extract category
info['category'] = await self._extract_category_from_ad_page()
Expand Down

0 comments on commit 6a315c9

Please sign in to comment.