Repository: alltheplaces/alltheplaces

Issue:
Kaufland Bulgaria
### Brand name

Kaufland

### Wikidata ID

Q685967

### Store finder url(s)

https://www.kaufland.bg/.klstorefinder.json


Discussion:

Resolving patch:
diff --git a/locations/pipelines.py b/locations/pipelines.py
--- a/locations/pipelines.py
+++ b/locations/pipelines.py
@@ -83,6 +83,7 @@ def process_item(self, item, spider):
             if country := self.country_utils.country_code_from_url(item.get("website")):
                 spider.crawler.stats.inc_value("atp/field/country/from_website_url")
                 item["country"] = country
+                return item
 
             # Still no country set, try an offline reverse geocoder.
             lat, lon = item.get("lat"), item.get("lon")
@@ -90,6 +91,7 @@ def process_item(self, item, spider):
                 if c := reverse_geocode.search([(lat, lon)]):
                     spider.crawler.stats.inc_value("atp/field/country/from_reverse_geocoding")
                     item["country"] = c[0]["country_code"]
+                    return item
 
         return item
 
diff --git a/locations/spiders/kaufland.py b/locations/spiders/kaufland.py
--- a/locations/spiders/kaufland.py
+++ b/locations/spiders/kaufland.py
@@ -1,44 +1,44 @@
 import scrapy
 
+from locations.categories import Categories
 from locations.hours import OpeningHours
 from locations.items import GeojsonPointItem
 
 
 class KauflandSpider(scrapy.Spider):
     name = "kaufland"
-    item_attributes = {"brand": "Kaufland", "brand_wikidata": "Q685967"}
-    allowed_domains = ["kaufland.de"]
-    start_urls = [
-        "https://filiale.kaufland.de/.klstorefinder.json",
-    ]
-
-    def parse_hours(self, hours):
-        opening_hours = OpeningHours()
-        for hour in hours:
-            day, open_time, close_time = hour.split("|")
-            opening_hours.add_range(day=day[:2], open_time=open_time, close_time=close_time)
-
-        return opening_hours.as_opening_hours()
-
-    def parse(self, response):
-        stores = response.json()
-
-        for store in stores:
-            properties = {
-                "name": store["cn"],
-                "ref": store["n"],
-                "addr_full": store["sn"],
-                "city": store["t"],
-                "postcode": store["pc"],
-                "country": "DE",
-                "phone": store["p"],
-                "website": "https://www.kaufland.de/service/filiale.storeName={}.html".format(store["n"]),
-                "lat": float(store["lat"]),
-                "lon": float(store["lng"]),
-            }
-
-            hours = self.parse_hours(store["wod"])
-            if hours:
-                properties["opening_hours"] = hours
-
-            yield GeojsonPointItem(**properties)
+    item_attributes = {"brand": "Kaufland", "brand_wikidata": "Q685967", "extras": Categories.SHOP_SUPERMARKET.value}
+    website_formats = {
+        "https://www.kaufland.bg/.klstorefinder.json": "https://www.kaufland.bg/moyat-kaufland/uslugi/filiali/{}.html",
+        "https://www.kaufland.cz/.klstorefinder.json": "https://www.kaufland.cz/aktualne/servis/prodejna/{}.html",
+        "https://www.kaufland.hr/.klstorefinder.json": "https://www.kaufland.hr/usluge/poslovnica/{}.html",
+        "https://www.kaufland.md/ro/.klstorefinder.json": "https://www.kaufland.md/ro/utile/magazin/{}.html",
+        "https://www.kaufland.pl/.klstorefinder.json": "https://www.kaufland.pl/dla-klienta/sklepy/{}.html",
+        "https://www.kaufland.ro/.klstorefinder.json": "https://www.kaufland.ro/utile/magazin/{}.html",
+        "https://www.kaufland.sk/.klstorefinder.json": "https://www.kaufland.sk/servis/predajne/{}.html",
+        "https://filiale.kaufland.de/.klstorefinder.json": "https://filiale.kaufland.de/service/filiale/frankfurt-oder-spitzkrug-multi-center-{}.html",
+    }
+    start_urls = website_formats.keys()
+
+    def parse(self, response, **kwargs):
+        for location in response.json():
+            item = GeojsonPointItem()
+
+            item["ref"] = location["n"]
+            item["lat"] = location["lat"]
+            item["lon"] = location["lng"]
+            item["name"] = location["cn"]
+            item["phone"] = location["p"].replace("/", "")
+            item["postcode"] = location["pc"]
+            item["street_address"] = location["sn"]
+            item["city"] = location["t"]
+
+            oh = OpeningHours()
+            for rule in location["wod"]:
+                day, start_time, end_time = rule.split("|")
+                oh.add_range(day, start_time, end_time)
+            item["opening_hours"] = oh.as_opening_hours()
+
+            item["website"] = self.website_formats.get(response.url).format(location["friendlyUrl"])
+
+            yield item


Test patch: