mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 02:31:45 +01:00
feat: by default delete old ads after republishing #338
This commit is contained in:
@@ -224,7 +224,7 @@ Valid file extensions are `.json`, `.yaml` and `.yml`
|
|||||||
The following parameters can be configured:
|
The following parameters can be configured:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
# wild card patterns to select ad configuration files
|
# glob (wildcard) patterns to select ad configuration files
|
||||||
# if relative paths are specified, then they are relative to this configuration file
|
# if relative paths are specified, then they are relative to this configuration file
|
||||||
ad_files:
|
ad_files:
|
||||||
- "./**/ad_*.{json,yml,yaml}"
|
- "./**/ad_*.{json,yml,yaml}"
|
||||||
@@ -254,6 +254,11 @@ categories:
|
|||||||
Verschenken & Tauschen > Verleihen: 272/274
|
Verschenken & Tauschen > Verleihen: 272/274
|
||||||
Verschenken & Tauschen > Verschenken: 272/192
|
Verschenken & Tauschen > Verschenken: 272/192
|
||||||
|
|
||||||
|
# publishing configuration
|
||||||
|
publishing:
|
||||||
|
delete_old_ads: "AFTER_PUBLISH" # one of: AFTER_PUBLISH, BEFORE_PUBLISH, NEVER
|
||||||
|
delete_old_ads_by_title: true # only works if delete_old_ads is set to BEFORE_PUBLISH
|
||||||
|
|
||||||
# browser configuration
|
# browser configuration
|
||||||
browser:
|
browser:
|
||||||
# https://peter.sh/experiments/chromium-command-line-switches/
|
# https://peter.sh/experiments/chromium-command-line-switches/
|
||||||
|
|||||||
@@ -53,8 +53,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
|||||||
|
|
||||||
self.command = "help"
|
self.command = "help"
|
||||||
self.ads_selector = "due"
|
self.ads_selector = "due"
|
||||||
self.delete_old_ads = True
|
self.keep_old_ads = False
|
||||||
self.delete_ads_by_title = False
|
|
||||||
|
|
||||||
def __del__(self) -> None:
|
def __del__(self) -> None:
|
||||||
if self.file_log:
|
if self.file_log:
|
||||||
@@ -195,7 +194,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
|||||||
case "--force":
|
case "--force":
|
||||||
self.ads_selector = "all"
|
self.ads_selector = "all"
|
||||||
case "--keep-old":
|
case "--keep-old":
|
||||||
self.delete_old_ads = False
|
self.keep_old_ads = True
|
||||||
case "-v" | "--verbose":
|
case "-v" | "--verbose":
|
||||||
LOG.setLevel(logging.DEBUG)
|
LOG.setLevel(logging.DEBUG)
|
||||||
logging.getLogger("nodriver").setLevel(logging.INFO)
|
logging.getLogger("nodriver").setLevel(logging.INFO)
|
||||||
@@ -462,7 +461,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
|||||||
if csrf_token is None:
|
if csrf_token is None:
|
||||||
raise AssertionError("Expected CSRF Token not found in HTML content!")
|
raise AssertionError("Expected CSRF Token not found in HTML content!")
|
||||||
|
|
||||||
if self.delete_ads_by_title:
|
if self.config["publishing"]["delete_old_ads_by_title"]:
|
||||||
published_ads = json.loads((await self.web_request(f"{self.root_url}/m-meine-anzeigen-verwalten.json?sort=DEFAULT"))["content"])["ads"]
|
published_ads = json.loads((await self.web_request(f"{self.root_url}/m-meine-anzeigen-verwalten.json?sort=DEFAULT"))["content"])["ads"]
|
||||||
|
|
||||||
for published_ad in published_ads:
|
for published_ad in published_ads:
|
||||||
@@ -507,7 +506,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
|||||||
"""
|
"""
|
||||||
await self.assert_free_ad_limit_not_reached()
|
await self.assert_free_ad_limit_not_reached()
|
||||||
|
|
||||||
if self.delete_old_ads:
|
if self.config["publishing"]["delete_old_ads"] == "BEFORE_PUBLISH" and not self.keep_old_ads:
|
||||||
await self.delete_ad(ad_cfg)
|
await self.delete_ad(ad_cfg)
|
||||||
|
|
||||||
LOG.info("Publishing ad '%s'...", ad_cfg["title"])
|
LOG.info("Publishing ad '%s'...", ad_cfg["title"])
|
||||||
@@ -677,6 +676,9 @@ class KleinanzeigenBot(WebScrapingMixin):
|
|||||||
|
|
||||||
utils.save_dict(ad_file, ad_cfg_orig)
|
utils.save_dict(ad_file, ad_cfg_orig)
|
||||||
|
|
||||||
|
if self.config["publishing"]["delete_old_ads"] == "AFTER_PUBLISH" and not self.keep_old_ads:
|
||||||
|
await self.delete_ad(ad_cfg)
|
||||||
|
|
||||||
async def __set_condition(self, condition_value: str) -> None:
|
async def __set_condition(self, condition_value: str) -> None:
|
||||||
condition_mapping = {
|
condition_mapping = {
|
||||||
"new_with_tag": "Neu mit Etikett",
|
"new_with_tag": "Neu mit Etikett",
|
||||||
|
|||||||
@@ -20,9 +20,15 @@ ad_defaults:
|
|||||||
|
|
||||||
# additional name to category ID mappings, see default list at
|
# additional name to category ID mappings, see default list at
|
||||||
# https://github.com/Second-Hand-Friends/kleinanzeigen-bot/blob/main/src/kleinanzeigen_bot/resources/categories.yaml
|
# https://github.com/Second-Hand-Friends/kleinanzeigen-bot/blob/main/src/kleinanzeigen_bot/resources/categories.yaml
|
||||||
# Notebooks: 161/278 # Elektronik > Notebooks
|
#
|
||||||
# Autoteile: 210/223/sonstige_autoteile # Auto, Rad & Boot > Autoteile & Reifen > Weitere Autoteile
|
# categories:
|
||||||
categories: []
|
# Elektronik > Notebooks: 161/278
|
||||||
|
# Jobs > Praktika: 102/125
|
||||||
|
categories: {}
|
||||||
|
|
||||||
|
publishing:
|
||||||
|
delete_old_ads: "AFTER_PUBLISH" # one of: AFTER_PUBLISH, BEFORE_PUBLISH, NEVER
|
||||||
|
delete_old_ads_by_title: true # only works if delete_old_ads is set to BEFORE_PUBLISH
|
||||||
|
|
||||||
# browser configuration
|
# browser configuration
|
||||||
browser:
|
browser:
|
||||||
|
|||||||
Reference in New Issue
Block a user