mirror of
https://github.com/Second-Hand-Friends/kleinanzeigen-bot.git
synced 2026-03-12 02:31:45 +01:00
@@ -323,6 +323,7 @@ shipping_costs: # e.g. 2.95
|
|||||||
# - Hermes_M
|
# - Hermes_M
|
||||||
# possible package types for size L:
|
# possible package types for size L:
|
||||||
# - DHL_10
|
# - DHL_10
|
||||||
|
# - DHL_20
|
||||||
# - DHL_31,5
|
# - DHL_31,5
|
||||||
# - Hermes_L
|
# - Hermes_L
|
||||||
shipping_options: []
|
shipping_options: []
|
||||||
|
|||||||
@@ -621,7 +621,8 @@ class KleinanzeigenBot(WebScrapingMixin):
|
|||||||
await self.__set_shipping_options(ad_cfg)
|
await self.__set_shipping_options(ad_cfg)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
await self.web_click(By.CSS_SELECTOR, '[class*="jsx-2623555103"]')
|
await self.web_click(By.XPATH,
|
||||||
|
'//*[contains(@class, "ShippingSection")]//*//button[contains(@aria-label, "Dialog mit Optionen öffnen")]')
|
||||||
await self.web_click(By.CSS_SELECTOR, '[class*="CarrierSelectionModal--Button"]')
|
await self.web_click(By.CSS_SELECTOR, '[class*="CarrierSelectionModal--Button"]')
|
||||||
await self.web_click(By.CSS_SELECTOR, '[class*="CarrierOption--Main"]')
|
await self.web_click(By.CSS_SELECTOR, '[class*="CarrierOption--Main"]')
|
||||||
if ad_cfg["shipping_costs"]:
|
if ad_cfg["shipping_costs"]:
|
||||||
@@ -852,6 +853,7 @@ class KleinanzeigenBot(WebScrapingMixin):
|
|||||||
"DHL_5": ("Mittel", "Paket 5 kg"),
|
"DHL_5": ("Mittel", "Paket 5 kg"),
|
||||||
"Hermes_M": ("Mittel", "M-Paket"),
|
"Hermes_M": ("Mittel", "M-Paket"),
|
||||||
"DHL_10": ("Groß", "Paket 10 kg"),
|
"DHL_10": ("Groß", "Paket 10 kg"),
|
||||||
|
"DHL_20": ("Groß", "Paket 20 kg"),
|
||||||
"DHL_31,5": ("Groß", "Paket 31,5 kg"),
|
"DHL_31,5": ("Groß", "Paket 31,5 kg"),
|
||||||
"Hermes_L": ("Groß", "L-Paket"),
|
"Hermes_L": ("Groß", "L-Paket"),
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import urllib.request as urllib_request
|
|||||||
import mimetypes
|
import mimetypes
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from typing import Any, Final
|
from typing import Any, Final
|
||||||
|
import json
|
||||||
|
|
||||||
from .i18n import get_translating_logger, pluralize
|
from .i18n import get_translating_logger, pluralize
|
||||||
from .utils import is_integer, parse_decimal, save_dict
|
from .utils import is_integer, parse_decimal, save_dict
|
||||||
@@ -347,23 +348,35 @@ class AdExtractor(WebScrapingMixin):
|
|||||||
ship_type = 'SHIPPING'
|
ship_type = 'SHIPPING'
|
||||||
ship_costs = float(parse_decimal(shipping_price_parts[-2]))
|
ship_costs = float(parse_decimal(shipping_price_parts[-2]))
|
||||||
|
|
||||||
# extract shipping options
|
# reading shipping option from kleinanzeigen
|
||||||
# It is only possible the extract the cheapest shipping option,
|
# and find the right one by price
|
||||||
# as the other options are not shown
|
shipping_costs = json.loads(
|
||||||
|
(await self.web_request("https://gateway.kleinanzeigen.de/postad/api/v1/shipping-options?posterType=PRIVATE"))
|
||||||
|
["content"])["data"]["shippingOptionsResponse"]["options"]
|
||||||
|
|
||||||
|
internal_shipping_opt = [x for x in shipping_costs if x["priceInEuroCent"] == ship_costs * 100]
|
||||||
|
|
||||||
|
if not internal_shipping_opt:
|
||||||
|
return 'NOT_APPLICABLE', ship_costs, shipping_options
|
||||||
|
|
||||||
|
# map to internal shipping identifiers used by kleinanzeigen-bot
|
||||||
shipping_option_mapping = {
|
shipping_option_mapping = {
|
||||||
"DHL_2": "5,49",
|
"DHL_001": "DHL_2",
|
||||||
"Hermes_Päckchen": "4,50",
|
"DHL_002": "DHL_5",
|
||||||
"Hermes_S": "4,95",
|
"DHL_003": "DHL_10",
|
||||||
"DHL_5": "6,99",
|
"DHL_004": "DHL_31,5",
|
||||||
"Hermes_M": "6,75",
|
"DHL_005": "DHL_20",
|
||||||
"DHL_10": "10,49",
|
"HERMES_001": "Hermes_Päckchen",
|
||||||
"DHL_31,5": "19,99",
|
"HERMES_002": "Hermes_S",
|
||||||
"Hermes_L": "10,95",
|
"HERMES_003": "Hermes_M",
|
||||||
|
"HERMES_004": "Hermes_L"
|
||||||
}
|
}
|
||||||
for shipping_option, shipping_price in shipping_option_mapping.items():
|
|
||||||
if shipping_price in shipping_text:
|
shipping_option = shipping_option_mapping.get(internal_shipping_opt[0]['id'])
|
||||||
shipping_options = [shipping_option]
|
if not shipping_option:
|
||||||
break
|
return 'NOT_APPLICABLE', ship_costs, shipping_options
|
||||||
|
|
||||||
|
shipping_options = [shipping_option]
|
||||||
except TimeoutError: # no pricing box -> no shipping given
|
except TimeoutError: # no pricing box -> no shipping given
|
||||||
ship_type = 'NOT_APPLICABLE'
|
ship_type = 'NOT_APPLICABLE'
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user