From 066ecc87b84e86517e8ef45d9d16f97b28c480bb Mon Sep 17 00:00:00 2001 From: Heavenfighter <33938595+Heavenfighter@users.noreply.github.com> Date: Thu, 8 Jan 2026 22:16:46 +0100 Subject: [PATCH] fix: take care of changed belen_conf keys (#758) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## â„šī¸ Description This PR takes care of the changed belen_conf dictionary. So extracting special attributes and third category will work again. - Link to the related issue(s): Issue #757 ## 📋 Changes Summary - changed belen_conf keys from "dimension108" to "ad_attributes" and "dimension92" to "l3_category_id" ### âš™ī¸ Type of Change Select the type(s) of change(s) included in this pull request: - [x] 🐞 Bug fix (non-breaking change which fixes an issue) - [ ] ✨ New feature (adds new functionality without breaking existing usage) - [ ] đŸ’Ĩ Breaking change (changes that might break existing user setups, scripts, or configurations) ## ✅ Checklist Before requesting a review, confirm the following: - [x] I have reviewed my changes to ensure they meet the project's standards. - [x] I have tested my changes and ensured that all tests pass (`pdm run test`). - [x] I have formatted the code (`pdm run format`). - [x] I have verified that linting passes (`pdm run lint`). - [x] I have updated documentation where necessary. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice. ## Summary by CodeRabbit * **Chores** * Updated internal data extraction sources for category and attribute information to align with current analytics configuration. * Updated test suite to reflect configuration changes. âœī¸ Tip: You can customize this high-level summary in your review settings. Co-authored-by: Jens <1742418+1cu@users.noreply.github.com> --- src/kleinanzeigen_bot/extract.py | 8 +++---- tests/unit/test_extract.py | 40 ++++++++++++++++---------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/kleinanzeigen_bot/extract.py b/src/kleinanzeigen_bot/extract.py index a56c0c1..6cf71cc 100644 --- a/src/kleinanzeigen_bot/extract.py +++ b/src/kleinanzeigen_bot/extract.py @@ -325,10 +325,10 @@ class AdExtractor(WebScrapingMixin): info["category"] = await self._extract_category_from_ad_page() # append subcategory and change e.g. category "161/172" to "161/172/lautsprecher_kopfhoerer" - # take subcategory from dimension92 as key 'art_s' sometimes is a special attribute (e.g. gender for clothes) + # take subcategory from third_category_name as key 'art_s' sometimes is a special attribute (e.g. gender for clothes) # the subcategory isn't really necessary, but when set, the appropriate special attribute gets preselected - if dimension92 := belen_conf["universalAnalyticsOpts"]["dimensions"].get("dimension92"): - info["category"] += f"/{dimension92}" + if third_category_id := belen_conf["universalAnalyticsOpts"]["dimensions"].get("l3_category_id"): + info["category"] += f"/{third_category_id}" info["title"] = title @@ -498,7 +498,7 @@ class AdExtractor(WebScrapingMixin): """ # e.g. "art_s:lautsprecher_kopfhoerer|condition_s:like_new|versand_s:t" - special_attributes_str = belen_conf["universalAnalyticsOpts"]["dimensions"].get("dimension108") + special_attributes_str = belen_conf["universalAnalyticsOpts"]["dimensions"].get("ad_attributes") if not special_attributes_str: return {} special_attributes = dict(item.split(":") for item in special_attributes_str.split("|") if ":" in item) diff --git a/tests/unit/test_extract.py b/tests/unit/test_extract.py index 63db581..361ff9f 100644 --- a/tests/unit/test_extract.py +++ b/tests/unit/test_extract.py @@ -17,7 +17,7 @@ from kleinanzeigen_bot.utils.web_scraping_mixin import Browser, By, Element class _DimensionsDict(TypedDict): - dimension108:str + ad_attributes:str class _UniversalAnalyticsOptsDict(TypedDict): @@ -622,8 +622,8 @@ class TestAdExtractorContent: web_execute = AsyncMock(return_value = { "universalAnalyticsOpts": { "dimensions": { - "dimension92": "", - "dimension108": "" + "l3_category_id": "", + "ad_attributes": "" } } }), @@ -658,8 +658,8 @@ class TestAdExtractorContent: web_execute = AsyncMock(return_value = { "universalAnalyticsOpts": { "dimensions": { - "dimension92": "", - "dimension108": "" + "l3_category_id": "", + "ad_attributes": "" } } }), @@ -699,8 +699,8 @@ class TestAdExtractorContent: web_execute = AsyncMock(return_value = { "universalAnalyticsOpts": { "dimensions": { - "dimension92": "", - "dimension108": "" + "l3_category_id": "", + "ad_attributes": "" } } }), @@ -841,7 +841,7 @@ class TestAdExtractorCategory: mock_web_execute.return_value = { "universalAnalyticsOpts": { "dimensions": { - "dimension108": "" + "ad_attributes": "" } } } @@ -856,7 +856,7 @@ class TestAdExtractorCategory: special_atts = { "universalAnalyticsOpts": { "dimensions": { - "dimension108": "versand_s:t|color_s:creme|groesse_s:68|condition_s:alright|type_s:accessoires|art_s:maedchen" + "ad_attributes": "versand_s:t|color_s:creme|groesse_s:68|condition_s:alright|type_s:accessoires|art_s:maedchen" } } } @@ -876,12 +876,12 @@ class TestAdExtractorCategory: @pytest.mark.asyncio # pylint: disable=protected-access - async def test_extract_special_attributes_missing_dimension108(self, extractor:AdExtractor) -> None: - """Test extraction of special attributes when dimension108 key is missing.""" + async def test_extract_special_attributes_missing_ad_attributes(self, extractor:AdExtractor) -> None: + """Test extraction of special attributes when ad_attributes key is missing.""" belen_conf:dict[str, Any] = { "universalAnalyticsOpts": { "dimensions": { - # dimension108 key is completely missing + # ad_attributes key is completely missing } } } @@ -1086,8 +1086,8 @@ class TestAdExtractorDownload: patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = { "universalAnalyticsOpts": { "dimensions": { - "dimension92": "", - "dimension108": "" + "l3_category_id": "", + "ad_attributes": "" } } }), @@ -1145,8 +1145,8 @@ class TestAdExtractorDownload: patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = { "universalAnalyticsOpts": { "dimensions": { - "dimension92": "", - "dimension108": "" + "l3_category_id": "", + "ad_attributes": "" } } }), @@ -1206,8 +1206,8 @@ class TestAdExtractorDownload: patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = { "universalAnalyticsOpts": { "dimensions": { - "dimension92": "", - "dimension108": "" + "l3_category_id": "", + "ad_attributes": "" } } }), @@ -1262,8 +1262,8 @@ class TestAdExtractorDownload: patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = { "universalAnalyticsOpts": { "dimensions": { - "dimension92": "", - "dimension108": "" + "l3_category_id": "", + "ad_attributes": "" } } }),