Repository: alltheplaces/alltheplaces

Issue:
Use clean_address function to join multiple free text lines together
The `clean_address` method added in #7568 allows a standardised approach to taking messy ordered multiple line address strings (of any type of composition) and joining them together into a single string.

We can now use `clean_address` to replace the many variants throughout spiders of attempting to join these multi-line address strings. An added benefit is being able to quickly find where multi-line address strings are parsed (via searching for `clean_address` instances), making it easier to change address handling in the future.

Related to #5598


Discussion:

Resolving patch:
diff --git a/locations/spiders/woolworths_au.py b/locations/spiders/woolworths_au.py
--- a/locations/spiders/woolworths_au.py
+++ b/locations/spiders/woolworths_au.py
@@ -1,6 +1,7 @@
 import scrapy
 
 from locations.dict_parser import DictParser
+from locations.pipelines.address_clean_up import clean_address
 
 
 class WoolworthsAUSpider(scrapy.Spider):
@@ -20,7 +21,7 @@ def parse(self, response):
             if not i["IsOpen"]:
                 continue
 
-            i["street_address"] = ", ".join(filter(None, [i["AddressLine1"], i["AddressLine2"]]))
+            i["street_address"] = clean_address([i["AddressLine1"], i["AddressLine2"]])
             i["ref"] = i.pop("StoreNo")
             i["city"] = i.pop("Suburb")
 
diff --git a/locations/spiders/zambrero_au.py b/locations/spiders/zambrero_au.py
--- a/locations/spiders/zambrero_au.py
+++ b/locations/spiders/zambrero_au.py
@@ -6,6 +6,7 @@
 from locations.categories import Categories
 from locations.hours import OpeningHours
 from locations.items import Feature
+from locations.pipelines.address_clean_up import clean_address
 
 
 class ZambreroAUSpider(Spider):
@@ -27,11 +28,9 @@ def parse_location(self, response):
             "name": re.sub(r"\s+", " ", response.xpath("//div[@data-location-id]/h4/text()").get()).strip(),
             "lat": response.xpath("//@data-lat").get(),
             "lon": response.xpath("///@data-lng").get(),
-            "addr_full": re.sub(
-                r"\s+",
-                " ",
-                " ".join(response.xpath('//div[@data-location-id]//span[contains(@class, "address")]/text()').getall()),
-            ).strip(),
+            "addr_full": clean_address(
+                " ".join(response.xpath('//div[@data-location-id]//span[contains(@class, "address")]/text()').getall())
+            ),
             "phone": response.xpath('//a[contains(@class, "phone")]/@href').get().replace("tel:", ""),
             "email": response.xpath('//a[contains(@href, "mailto:")]/@href').get().replace("mailto:", ""),
             "website": response.url,
diff --git a/locations/spiders/zizzi_gb.py b/locations/spiders/zizzi_gb.py
--- a/locations/spiders/zizzi_gb.py
+++ b/locations/spiders/zizzi_gb.py
@@ -1,6 +1,7 @@
 import scrapy
 
 from locations.dict_parser import DictParser
+from locations.pipelines.address_clean_up import clean_address
 
 
 class ZizziGBSpider(scrapy.Spider):
@@ -11,7 +12,7 @@ class ZizziGBSpider(scrapy.Spider):
     def parse(self, response):
         for store in response.json()["data"]:
             item = DictParser.parse(store)
-            item["addr_full"] = ", ".join(store["address"].split("\r\n"))
+            item["addr_full"] = clean_address(store["address"].split("\r\n"))
             item["image"] = store["featured_image"]
             item["website"] = store["link"]
 


Test patch: