mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 10:31:50 +01:00
feat: by default delete old ads after republishing #338
This commit is contained in:
@@ -53,8 +53,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
|
||||
self.command = "help"
|
||||
self.ads_selector = "due"
|
||||
self.delete_old_ads = True
|
||||
self.delete_ads_by_title = False
|
||||
self.keep_old_ads = False
|
||||
|
||||
def __del__(self) -> None:
|
||||
if self.file_log:
|
||||
@@ -195,7 +194,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
case "--force":
|
||||
self.ads_selector = "all"
|
||||
case "--keep-old":
|
||||
self.delete_old_ads = False
|
||||
self.keep_old_ads = True
|
||||
case "-v" | "--verbose":
|
||||
LOG.setLevel(logging.DEBUG)
|
||||
logging.getLogger("nodriver").setLevel(logging.INFO)
|
||||
@@ -462,7 +461,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
if csrf_token is None:
|
||||
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"]
|
||||
|
||||
for published_ad in published_ads:
|
||||
@@ -507,7 +506,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
"""
|
||||
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)
|
||||
|
||||
LOG.info("Publishing ad '%s'...", ad_cfg["title"])
|
||||
@@ -677,6 +676,9 @@ class KleinanzeigenBot(WebScrapingMixin):
|
||||
|
||||
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:
|
||||
condition_mapping = {
|
||||
"new_with_tag": "Neu mit Etikett",
|
||||
|
||||
@@ -20,9 +20,15 @@ ad_defaults:
|
||||
|
||||
# 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
|
||||
# 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:
|
||||
|
||||
Reference in New Issue
Block a user