refactor: remove deprecated category aliases (#1397)

## ℹ️ Description
Removes `categories_old.yaml`, the 145 deprecated category aliases (e.g.
`Handy_Apple`) that were kept "for backward compatibility" since
2024-11.

- Related: #1388, #1396
- Motivation: category selection now uses the site's live data, and
names that are not in `categories.yaml` are resolved while publishing.
The deprecated file only kept very old ad files working and is no longer
worth maintaining. Only one key (`Elektronik`, same value) overlapped
with `categories.yaml`.

## 📋 Changes Summary

- Delete `categories_old.yaml` and stop loading it in
`runtime_config.load_config`.
- Drop `category_labels` (added in #1395 only to exclude the deprecated
aliases); with the file gone it equals `categories`. The category dialog
now reads `categories`.
- Remove the obsolete log translation; adjust tests and add a case for a
removed alias.
- A removed alias such as `category: Handy_Apple` now fails with a
`CategoryResolutionError` that lists the categories Kleinanzeigen
offers. Use a name from `categories.yaml` or a category ID instead.
- No config, schema or documentation changes.

### ⚙️ Type of Change
- [ ] 🐞 Bug fix (non-breaking change which fixes an issue)
- [ ] ✨ New feature (adds new functionality without breaking existing
usage)
- [x] 💥 Breaking change (changes that might break existing user setups,
scripts, or configurations)

## ✅ Checklist
- [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
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Changes**
* Category selection now uses the category mappings from the current
configuration.
* Legacy category aliases are no longer loaded, so listings that rely on
deprecated names may need to use the corresponding category from
`categories.yaml` instead.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Jens authored and GitHub committed 2026-11-14 17:43:31 +01:00
1 parent 672104e9d5
commit 2687db605f
7 files changed
+12 -225

No files matched your search

-2
View File
@@ -52,7 +52,6 @@ class KleinanzeigenBot(WebScrapingMixin): # noqa: PLR0904
self._workspace_mode_arg:_xdg_paths.InstallationMode | None = None
self.categories:dict[str, str] = {}
self.category_labels:dict[str, str] = {}
self.file_log:_loggers.LogFileHandle | None = None
self._log_basename = os.path.splitext(os.path.basename(sys.executable))[0] if is_frozen() else "kleinanzeigen_bot"
@@ -183,7 +182,6 @@ class KleinanzeigenBot(WebScrapingMixin): # noqa: PLR0904
runtime_state = _runtime_config.load_config(self.config_file_path, self.workspace, self.command)
self.config = runtime_state.config
self.categories = runtime_state.categories
self.category_labels = runtime_state.category_labels
self._timing_collector = runtime_state.timing_collector
_runtime_config.apply_browser_config(self.browser_config, self.config, self.workspace, self.config_file_path)
+1 -1
View File
@@ -223,7 +223,7 @@ async def _set_category_in_dialog(
product_title:str | None = None,
) -> None:
"""Select a configured category path in Kleinanzeigen's redesigned dialog."""
categories = getattr(web, "category_labels", {})
categories = getattr(web, "categories", {})
if not isinstance(categories, Mapping):
categories = {}
label_options = _category_dialog_label_options(category, categories, product_title = product_title)
@@ -1,200 +0,0 @@
###############################################################################
# Deprecated category names for backward compatiblity, don't use them anymore!
###############################################################################
# Elektronik
Elektronik: 161/168
## Audio & Hifi
Audio_und_Hifi: 161/172/sonstiges
CD_Player: 161/172/cd_player
Kopfhörer: 161/172/lautsprecher_kopfhoerer
Lautsprecher: 161/172/lautsprecher_kopfhoerer
MP3_Player: 161/172/mp3_player
Radio: 161/172/radio_receiver
Reciver: 161/172/radio_receiver
Stereoanlagen: 161/172/stereoanlagen
## Dienstleistungen Elektronik
Dienstleistungen_Elektronik: 161/226
## Foto
Foto: 161/245/other
Kameras: 161/245/camera
Objektive: 161/245/lens
Foto_Zubehör: 161/245/equipment
Kamera_Equipment: 161/245/camera_and_equipment
## Handy & Telefon
Handys: 161/173/sonstige
Handy_Apple: 161/173/apple
Handy_HTC: 161/173/htc_handy
Handy_LG: 161/173/lg_handy
Handy_Motorola: 161/173/motorola_handy
Handy_Nokia: 161/173/nokia_handy
Handy_Samsung: 161/173/samsung_handy
Handy_Siemens: 161/173/siemens_handy
Handy_Sony: 161/173/sony_handy
Faxgeräte: 161/173/faxgeraete
Telefone: 161/173/telefone
## Haushaltsgeräte
Haushaltsgeräte: 161/176/sonstige
Haushaltkleingeräte: 161/176/haushaltskleingeraete
Herde: 161/176/herde_backoefen
Backöfen: 161/176/herde_backoefen
Kaffemaschinen: 161/176/kaffee_espressomaschinen
Espressomaschinen: 161/176/kaffee_espressomaschinen
Kühlschränke: 161/176/kuehlschraenke_gefriergeraete
Gefriergeräte: 161/176/kuehlschraenke_gefriergeraete
Spülmaschinen: 161/176/spuelmaschinen
Staubsauger: 161/176/staubsauger
Waschmaschinen: 161/176/waschmaschinen_trockner
Trockner: 161/176/waschmaschinen_trockner
## Konsolen
Konsolen: 161/279/weitere
Pocket_Konsolen: 161/279/dsi_psp
Playstation: 161/279/playstation
XBox: 161/279/xbox
Wii: 161/279/wii
## Notebooks
Notebooks: 161/278
## PCs
PCs: 161/228
## PC-Zubehör & Software
PC-Zubehör: 161/225/sonstiges
Drucker: 161/225/drucker_scanner
Scanner: 161/225/drucker_scanner
Festplatten: 161/225/festplatten_laufwerke
Laufwerke: 161/225/festplatten_laufwerke
Gehäuse: 161/225/gehaeuse
Grafikkarten: 161/225/grafikkarten
Kabel: 161/225/kabel_adapter
Adapter: 161/225/kabel_adapter
Mainboards: 161/225/mainboards
Monitore: 161/225/monitore
Multimedia: 161/225/multimedia
Netzwerk: 161/225/netzwerk_modem
CPUs: 161/225/prozessor_cpu
Prozessoren: 161/225/prozessor_cpu
Speicher: 161/225/speicher
Software: 161/225/software
Mäuse: 161/225/tastatur_maus
Tastaturen: 161/225/tastatur_maus
## Tablets & Reader
Tablets_Reader: 161/285/weitere
iPad: 161/285/ipad
Kindle: 161/285/kindle
Tablets_Samsung: 161/285/samsung_tablets
## TV & Video
TV_Video: 161/175/weitere
DVD-Player: 161/175/dvdplayer_recorder
Recorder: 161/175/dvdplayer_recorder
Fernseher: 161/175/fernseher
Reciever: 161/175/tv_receiver
## Videospiele
Videospiele: 161/227/sonstige
Videospiele_DS: 161/227/dsi_psp
Videospiele_PSP: 161/227/dsi_psp
Videospiele_Nintendo: 161/227/nintendo
Videospiele_Playstation: 161/227/playstation
Videospiele_XBox: 161/227/xbox
Videospiele_Wii: 161/227/wii
Videospiele_PC: 161/227/pc_spiele
# Auto, Rad & Boot
Autoreifen: 210/223/reifen_felgen
# Freizeit, Hobby & Nachbarschaft
Sammeln: 185/234/sonstige
# Mode & Beauty
Beauty: 153/224/sonstiges
Gesundheit: 153/224/gesundheit
Mode: 153/155
# Mode & Beauty > Damenschuhe
Damenschuhe: 153/159/sonstiges
Damen_Ballerinas: 153/159/ballerinas
Damen_Halbschuhe: 153/159/halb_schnuerschuhe
Damen_Hausschuhe: 153/159/hausschuhe
Damen_High_Heels: 153/159/pumps
Damen_Pumps: 153/159/pumps
Damen_Sandalen: 153/159/sandalen
Damen_Schnürschuhe: 153/159/halb_schnuerschuhe
Damen_Sportschuche: 153/159/sneaker_sportschuhe
Damen_Sneaker: 153/159/sneaker_sportschuhe
Damen_Stiefel: 153/159/stiefel
Damen_Stiefeletten: 153/159/stiefel
Damen_Outdoorschuhe: 153/159/outdoor_wanderschuhe
Damen_Wanderschuhe: 153/159/outdoor_wanderschuhe
# Mode & Beauty > Herrenschuhe
Herrenschuhe: 153/158/sonstiges
Herren_Halbschuhe: 153/158/halb_schnuerschuhe
Herren_Hausschuhe: 153/158/hausschuhe
Herren_Sandalen: 153/158/sandalen
Herren_Schnürschuhe: 153/158/halb_schnuerschuhe
Herren_Sportschuche: 153/158/sneaker_sportschuhe
Herren_Sneaker: 153/158/sneaker_sportschuhe
Herren_Stiefel: 153/158/stiefel
Herren_Stiefeletten: 153/158/stiefel
Herren_Outdoorschuhe: 153/158/outdoor_wanderschuhe
Herren_Wanderschuhe: 153/158/outdoor_wanderschuhe
# Familie, Kind & Baby
Familie_Kind_Baby: 17/18
Altenpflege: 17/236
Babysitter: 17/237
Buggys: 17/25
Babyschalen: 17/21
Baby-Ausstattung: 17/258
Kinderbetreuung: 17/237
Kindersitze: 17/21
Kinderwagen: 17/25
# Familie, Kind & Baby > Spielzeug
Spielzeug: 17/23/sonstiges
Actionfiguren: 17/23/actionfiguren
Babyspielzeug: 17/23/babyspielzeug
Barbie: 17/23/barbie
Dreirad: 17/23/dreirad
Gesellschaftsspiele: 17/23/gesellschaftsspiele
Holzspielzeug: 17/23/holzspielzeug
Duplo: 17/23/lego_duplo
LEGO: 17/23/lego_duplo
Lernspielzeug: 17/23/lernspielzeug
Playmobil: 17/23/playmobil
Puppen: 17/23/puppen
Spielzeugautos: 17/23/spielzeug_autos
Spielzeug_draussen: 17/23/spielzeug_draussen
Stofftiere: 17/23/stofftiere
# Haus & Garten > Wohnzimmer
Wohnzimmer_Regale: 80/88/regale
Wohnzimmer_Schraenke: 80/88/schraenke
Wohnzimmer_Sitzmoebel: 80/88/sitzmoebel
Wohnzimmer_Sofas_Sitzgarnituren: 80/88/sofas_sitzgarnituren
Wohnzimmer_Tische: 80/88/tische
Wohnzimmer_TV_Moebel: 80/88/tv_moebel
Wohnzimmer_Sonstiges: 80/88/sonstiges
# Verschenken & Tauschen
Tauschen: 272/273
Verleihen: 272/274
Verschenken: 272/192
@@ -51,7 +51,6 @@ kleinanzeigen_bot/runtime_config.py:
load_config:
"config": "Konfiguration"
"Loaded %s categories from categories.yaml": "%s Kategorien aus categories.yaml geladen"
"Loaded %s categories from categories_old.yaml": "%s Kategorien aus categories_old.yaml geladen"
"Loaded %s categories from config.yaml (custom)": "%s Kategorien aus config.yaml geladen (benutzerdefiniert)"
"Loaded %s categories in total": "%s Kategorien insgesamt geladen"
"No categories loaded - category files may be missing or empty": "Keine Kategorien geladen - Kategorie-Dateien fehlen oder sind leer"
+2 -10
View File
@@ -13,7 +13,6 @@ import os
import re
import sys
from dataclasses import dataclass
from dataclasses import field as dataclass_field
from gettext import gettext as _
from pathlib import Path
from typing import Any, Final
@@ -47,8 +46,6 @@ class RuntimeState:
config:Config
categories:dict[str, str]
timing_collector:TimingCollector | None
# Names that may be shown in the category dialog: no deprecated aliases, which only resolve names to IDs.
category_labels:dict[str, str] = dataclass_field(default_factory = dict)
def create_default_config(config_file_path:str, workspace:_xdg_paths.Workspace | None) -> None:
@@ -133,23 +130,18 @@ def load_config(config_file_path:str, workspace:_xdg_paths.Workspace | None, com
# No workspace or disabled timing collection means we skip the collector entirely.
timing_collector = None
# Merge order matters: bundled defaults first, deprecated aliases second, user overrides last.
# Merge order matters: bundled defaults first, user overrides last.
categories:dict[str, str] = _dicts.load_dict_from_module(_resources, "categories.yaml", "")
LOG.debug("Loaded %s categories from categories.yaml", len(categories))
category_labels = dict(categories)
deprecated_categories = _dicts.load_dict_from_module(_resources, "categories_old.yaml", "")
LOG.debug("Loaded %s categories from categories_old.yaml", len(deprecated_categories))
categories.update(deprecated_categories)
if config.categories:
categories.update(config.categories)
category_labels.update(config.categories)
LOG.debug("Loaded %s categories from config.yaml (custom)", len(config.categories))
if not categories:
# This should only happen if resources are broken or empty, so surface it loudly.
LOG.warning("No categories loaded - category files may be missing or empty")
LOG.debug("Loaded %s categories in total", len(categories))
return RuntimeState(config = config, categories = categories, timing_collector = timing_collector, category_labels = category_labels)
return RuntimeState(config = config, categories = categories, timing_collector = timing_collector)
def apply_browser_config(browser_config:Any, config:Config, workspace:_xdg_paths.Workspace | None, config_file_path:str) -> None:
+8 -7
View File
@@ -686,7 +686,8 @@ class TestCategoryProbeBehavior:
assert ("Offered values: Smartphones, Videospiele" in caplog.text) is isinstance(lookup, Exception)
@pytest.mark.asyncio
async def test_text_category_without_parent_alias_reports_the_offered_values(self, test_bot:KleinanzeigenBot) -> None:
@pytest.mark.parametrize("category", ["Elektronik > Dreamcast", "Handy_Apple"]) # unknown name, removed deprecated alias
async def test_text_category_without_parent_alias_reports_the_offered_values(self, test_bot:KleinanzeigenBot, category:str) -> None:
with (
patch(
"kleinanzeigen_bot.category_picker.resolve_category_text",
@@ -695,7 +696,7 @@ class TestCategoryProbeBehavior:
),
pytest.raises(CategoryResolutionError, match = "Offered values"),
):
await set_category(test_bot, category = "Elektronik > Dreamcast", ad_file = "ad.yaml")
await set_category(test_bot, category = category, ad_file = "ad.yaml")
@pytest.mark.asyncio
async def test_set_category_uses_probe_for_auto_selected_marker(self, test_bot:KleinanzeigenBot) -> None:
@@ -1037,7 +1038,7 @@ class TestRedesignedCategoryDialog:
@pytest.mark.unit
@pytest.mark.asyncio
async def test_category_dialog_uses_only_site_labels_when_available(self, test_bot:KleinanzeigenBot) -> None:
test_bot.category_labels = {
test_bot.categories = {
"Elektronik": "161",
"Elektronik > Videospiele": "161/227",
"Elektronik > Videospiele > PlayStation Spiele": "161/227/playstation",
@@ -1068,7 +1069,7 @@ class TestRedesignedCategoryDialog:
async def test_category_dialog_uses_yaml_labels_only_without_site_labels(
self, test_bot:KleinanzeigenBot, site_labels:dict[int, str], expected:list[str],
) -> None:
test_bot.category_labels = {"Elektronik": "161", "Elektronik > Handy & Telefon": "161/173"}
test_bot.categories = {"Elektronik": "161", "Elektronik > Handy & Telefon": "161/173"}
seen:list[list[str]] = []
async def click_level(_web:Any, _selector:str, _category:str, _depth:int, candidates:list[str]) -> str:
@@ -1090,7 +1091,7 @@ class TestRedesignedCategoryDialog:
@pytest.mark.asyncio
async def test_category_dialog_names_values_when_site_asks_for_one_more_level(self, test_bot:KleinanzeigenBot) -> None:
"""#1388: a console now opens a further level; the apply button stays disabled until it is chosen."""
test_bot.category_labels = {"Elektronik": "161", "Elektronik > Videospiele": "161/227"}
test_bot.categories = {"Elektronik": "161", "Elektronik > Videospiele": "161/227"}
async def click_level(_web:Any, _selector:str, _category:str, _depth:int, candidates:list[str]) -> str:
return candidates[0]
@@ -1143,7 +1144,7 @@ class TestRedesignedCategoryDialog:
self,
test_bot:KleinanzeigenBot,
) -> None:
test_bot.category_labels = {"Bekleidung": "17"}
test_bot.categories = {"Bekleidung": "17"}
category_button = MagicMock()
category_button.click = AsyncMock()
category_button.visible_text = "Bekleidung"
@@ -1174,7 +1175,7 @@ class TestRedesignedCategoryDialog:
@pytest.mark.asyncio
async def test_set_category_uses_visible_dialog_labels_and_applies_leaf(self, test_bot:KleinanzeigenBot) -> None:
category = "17/22/pullover_strickjacken"
test_bot.category_labels = {
test_bot.categories = {
"Familie, Kind & Baby > Baby- & Kinderkleidung > Pullover & Strickjacken": category,
}
clicked:list[str] = []
+1 -4
View File
@@ -127,9 +127,6 @@ publishing:
assert state.config.login.username == "fallback_user"
assert state.categories["Custom > Category"] == "1/2"
assert state.category_labels["Custom > Category"] == "1/2"
assert "Handy_Apple" in state.categories
assert "Handy_Apple" not in state.category_labels
assert state.timing_collector is None
def test_load_config_raises_for_missing_login_env(self, tmp_path:Path, monkeypatch:pytest.MonkeyPatch) -> None:
@@ -201,7 +198,7 @@ publishing:
load_dict_from_module = dicts.load_dict_from_module
def fake_load_dict_from_module(module:ModuleType, filename:str, content_label:str = "") -> dict[str, Any]:
if filename in {"categories.yaml", "categories_old.yaml"}:
if filename in {"categories.yaml"}:
return {}
return load_dict_from_module(module, filename, content_label)