mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
fix: take care of changed belen_conf keys (#758)
## ℹ️ 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. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## 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. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai --> Co-authored-by: Jens <1742418+1cu@users.noreply.github.com>
This commit is contained in:
@@ -325,10 +325,10 @@ class AdExtractor(WebScrapingMixin):
|
|||||||
info["category"] = await self._extract_category_from_ad_page()
|
info["category"] = await self._extract_category_from_ad_page()
|
||||||
|
|
||||||
# append subcategory and change e.g. category "161/172" to "161/172/lautsprecher_kopfhoerer"
|
# 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
|
# the subcategory isn't really necessary, but when set, the appropriate special attribute gets preselected
|
||||||
if dimension92 := belen_conf["universalAnalyticsOpts"]["dimensions"].get("dimension92"):
|
if third_category_id := belen_conf["universalAnalyticsOpts"]["dimensions"].get("l3_category_id"):
|
||||||
info["category"] += f"/{dimension92}"
|
info["category"] += f"/{third_category_id}"
|
||||||
|
|
||||||
info["title"] = title
|
info["title"] = title
|
||||||
|
|
||||||
@@ -498,7 +498,7 @@ class AdExtractor(WebScrapingMixin):
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
# e.g. "art_s:lautsprecher_kopfhoerer|condition_s:like_new|versand_s:t"
|
# 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:
|
if not special_attributes_str:
|
||||||
return {}
|
return {}
|
||||||
special_attributes = dict(item.split(":") for item in special_attributes_str.split("|") if ":" in item)
|
special_attributes = dict(item.split(":") for item in special_attributes_str.split("|") if ":" in item)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ from kleinanzeigen_bot.utils.web_scraping_mixin import Browser, By, Element
|
|||||||
|
|
||||||
|
|
||||||
class _DimensionsDict(TypedDict):
|
class _DimensionsDict(TypedDict):
|
||||||
dimension108:str
|
ad_attributes:str
|
||||||
|
|
||||||
|
|
||||||
class _UniversalAnalyticsOptsDict(TypedDict):
|
class _UniversalAnalyticsOptsDict(TypedDict):
|
||||||
@@ -622,8 +622,8 @@ class TestAdExtractorContent:
|
|||||||
web_execute = AsyncMock(return_value = {
|
web_execute = AsyncMock(return_value = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
"dimension92": "",
|
"l3_category_id": "",
|
||||||
"dimension108": ""
|
"ad_attributes": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -658,8 +658,8 @@ class TestAdExtractorContent:
|
|||||||
web_execute = AsyncMock(return_value = {
|
web_execute = AsyncMock(return_value = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
"dimension92": "",
|
"l3_category_id": "",
|
||||||
"dimension108": ""
|
"ad_attributes": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -699,8 +699,8 @@ class TestAdExtractorContent:
|
|||||||
web_execute = AsyncMock(return_value = {
|
web_execute = AsyncMock(return_value = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
"dimension92": "",
|
"l3_category_id": "",
|
||||||
"dimension108": ""
|
"ad_attributes": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -841,7 +841,7 @@ class TestAdExtractorCategory:
|
|||||||
mock_web_execute.return_value = {
|
mock_web_execute.return_value = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
"dimension108": ""
|
"ad_attributes": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -856,7 +856,7 @@ class TestAdExtractorCategory:
|
|||||||
special_atts = {
|
special_atts = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"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
|
@pytest.mark.asyncio
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
async def test_extract_special_attributes_missing_dimension108(self, extractor:AdExtractor) -> None:
|
async def test_extract_special_attributes_missing_ad_attributes(self, extractor:AdExtractor) -> None:
|
||||||
"""Test extraction of special attributes when dimension108 key is missing."""
|
"""Test extraction of special attributes when ad_attributes key is missing."""
|
||||||
belen_conf:dict[str, Any] = {
|
belen_conf:dict[str, Any] = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"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 = {
|
patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
"dimension92": "",
|
"l3_category_id": "",
|
||||||
"dimension108": ""
|
"ad_attributes": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -1145,8 +1145,8 @@ class TestAdExtractorDownload:
|
|||||||
patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = {
|
patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
"dimension92": "",
|
"l3_category_id": "",
|
||||||
"dimension108": ""
|
"ad_attributes": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -1206,8 +1206,8 @@ class TestAdExtractorDownload:
|
|||||||
patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = {
|
patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
"dimension92": "",
|
"l3_category_id": "",
|
||||||
"dimension108": ""
|
"ad_attributes": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
@@ -1262,8 +1262,8 @@ class TestAdExtractorDownload:
|
|||||||
patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = {
|
patch.object(extractor, "web_execute", new_callable = AsyncMock, return_value = {
|
||||||
"universalAnalyticsOpts": {
|
"universalAnalyticsOpts": {
|
||||||
"dimensions": {
|
"dimensions": {
|
||||||
"dimension92": "",
|
"l3_category_id": "",
|
||||||
"dimension108": ""
|
"ad_attributes": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user