From 3964a3a1d3fc0dfc222cc2d82cbf3d5ddeebfbe9 Mon Sep 17 00:00:00 2001 From: sebthom Date: Thu, 31 Mar 2022 23:26:57 +0200 Subject: [PATCH] Allow setting price-type to NOT_APPLICABLE. Addresses #52 --- README.md | 2 +- kleinanzeigen_bot/__init__.py | 13 ++++++++----- kleinanzeigen_bot/resources/ad_fields.yaml | 2 +- kleinanzeigen_bot/resources/config_defaults.yaml | 2 +- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d976b3d..6320d64 100644 --- a/README.md +++ b/README.md @@ -223,7 +223,7 @@ ad_defaults: description: prefix: "" suffix: "" - price_type: NEGOTIABLE # one of: FIXED, NEGOTIABLE, GIVE_AWAY + price_type: NEGOTIABLE # one of: FIXED, NEGOTIABLE, GIVE_AWAY, NOT_APPLICABLE shipping_type: SHIPPING # one of: PICKUP, SHIPPING, NOT_APPLICABLE shipping_costs: # e.g. 2.95 contact: diff --git a/kleinanzeigen_bot/__init__.py b/kleinanzeigen_bot/__init__.py index aa9e47e..30f2e66 100644 --- a/kleinanzeigen_bot/__init__.py +++ b/kleinanzeigen_bot/__init__.py @@ -240,8 +240,9 @@ class KleinanzeigenBot(SeleniumMixin): assert_one_of("type", ("OFFER", "WANTED")) assert_min_len("title", 10) assert_has_value("description") - assert_has_value("price") - assert_one_of("price_type", ("FIXED", "NEGOTIABLE", "GIVE_AWAY")) + assert_one_of("price_type", ("FIXED", "NEGOTIABLE", "GIVE_AWAY", "NOT_APPLICABLE")) + if ad_cfg["price_type"] != "NOT_APPLICABLE": + assert_has_value("price") assert_one_of("shipping_type", ("PICKUP", "SHIPPING", "NOT_APPLICABLE")) assert_has_value("contact.name") assert_has_value("republication_interval") @@ -415,9 +416,11 @@ class KleinanzeigenBot(SeleniumMixin): ############################# # set price ############################# - self.web_select(By.XPATH, "//select[@id='priceType']", ad_cfg["price_type"]) - if ad_cfg["price_type"] != "GIVE_AWAY": - self.web_input(By.ID, "pstad-price", ad_cfg["price"]) + price_type = ad_cfg["price_type"] + if price_type != "NOT_APPLICABLE": + self.web_select(By.XPATH, "//select[@id='priceType']", price_type) + if price_type != "GIVE_AWAY": + self.web_input(By.ID, "pstad-price", ad_cfg["price"]) ############################# # set description diff --git a/kleinanzeigen_bot/resources/ad_fields.yaml b/kleinanzeigen_bot/resources/ad_fields.yaml index ff105eb..8df9d2f 100644 --- a/kleinanzeigen_bot/resources/ad_fields.yaml +++ b/kleinanzeigen_bot/resources/ad_fields.yaml @@ -5,7 +5,7 @@ description: category: special_attributes: {} price: -price_type: # one of: FIXED, NEGOTIABLE, GIVE_AWAY +price_type: # one of: FIXED, NEGOTIABLE, GIVE_AWAY, NOT_APPLICABLE shipping_type: # one of: PICKUP, SHIPPING, NOT_APPLICABLE shipping_costs: images: [] diff --git a/kleinanzeigen_bot/resources/config_defaults.yaml b/kleinanzeigen_bot/resources/config_defaults.yaml index 4f17201..64a9b3e 100644 --- a/kleinanzeigen_bot/resources/config_defaults.yaml +++ b/kleinanzeigen_bot/resources/config_defaults.yaml @@ -10,7 +10,7 @@ ad_defaults: description: prefix: "" suffix: "" - price_type: NEGOTIABLE # one of: FIXED, NEGOTIABLE, GIVE_AWAY + price_type: NEGOTIABLE # one of: FIXED, NEGOTIABLE, GIVE_AWAY, NOT_APPLICABLE shipping_type: SHIPPING # one of: PICKUP, SHIPPING, NOT_APPLICABLE contact: name: ""