Repository: alltheplaces/alltheplaces

Issue:
Spider argos is broken
During the global build at 2021-08-25-14-42-15, spider **argos** failed with **0 features** and **0 errors**.

Here's [the log](https://data.alltheplaces.xyz/runs/2021-08-25-14-42-15/logs/argos.txt) and [the output](https://data.alltheplaces.xyz/runs/2021-08-25-14-42-15/output/argos.geojson) ([on a map](https://data.alltheplaces.xyz/map.html?show=https://data.alltheplaces.xyz/runs/2021-08-25-14-42-15/output/argos.geojson))
Spider argos is broken
During the global build at 2021-05-26-14-42-23, spider **argos** failed with **0 features** and **0 errors**.

Here's [the log](https://data.alltheplaces.xyz/runs/2021-05-26-14-42-23/logs/argos.log) and [the output](https://data.alltheplaces.xyz/runs/2021-05-26-14-42-23/output/argos.geojson) ([on a map](https://data.alltheplaces.xyz/map.html?show=https://data.alltheplaces.xyz/runs/2021-05-26-14-42-23/output/argos.geojson))


Discussion:

Resolving patch:
diff --git a/locations/spiders/argos.py b/locations/spiders/argos.py
--- a/locations/spiders/argos.py
+++ b/locations/spiders/argos.py
@@ -1,41 +1,58 @@
-import scrapy
 import re
 import json
-from locations.items import GeojsonPointItem
 
+from locations.items import GeojsonPointItem
+from locations.hours import OpeningHours
+from scrapy.spiders import SitemapSpider
 
-class ArgosSpider(scrapy.Spider):
 
+class ArgosSpider(SitemapSpider):
     name = "argos"
-    item_attributes = {"brand": "Argos"}
+    item_attributes = {"brand": "Argos", "brand_wikidata": "Q4789707"}
     allowed_domains = ["www.argos.co.uk"]
     download_delay = 0.5
-    start_urls = ("http://www.argos.co.uk/stores/",)
+    sitemap_urls = [
+        "https://www.argos.co.uk/stores_sitemap.xml",
+    ]
+    sitemap_rules = [
+        (
+            r"https://www.argos.co.uk/stores/([\d]+)-([\w-]+)",
+            "parse",
+        ),
+    ]
+    custom_settings = {
+        "USER_AGENT": "Mozilla/5.0 (X11; Linux x86_64; rv:99.0) Gecko/20100101 Firefox/99.0"
+    }
 
-    def parse_stores(self, response):
+    def parse(self, response):
         data = re.findall(r"window.INITIAL_STATE =[^<]+", response.text)
         json_data = json.loads(data[0].replace("window.INITIAL_STATE =", ""))
         properties = {
-            "addr_full": json_data["store"]["store"]["address"],
+            "street_address": json_data["store"]["store"]["address"],
             "phone": json_data["store"]["store"]["tel"],
             "city": json_data["store"]["store"]["town"],
-            "state": "",
+            "name": json_data["store"]["store"]["name"],
             "postcode": json_data["store"]["store"]["postcode"],
             "ref": json_data["store"]["store"]["id"],
             "website": response.url,
             "lat": float(json_data["store"]["store"]["lat"]),
             "lon": float(json_data["store"]["store"]["lng"]),
+            "extras": {
+                "store_type": json_data["store"]["store"]["type"],
+            },
         }
 
-        open_hours = ""
+        oh = OpeningHours()
         for item in json_data["store"]["store"]["storeTimes"]:
-            open_hours = open_hours + item["date"][:2] + " " + item["time"] + " ;"
-        if open_hours:
-            properties["opening_hours"] = open_hours
+            open_time, close_time = item["time"].split(" - ")
+            if (
+                open_time
+                and not open_time.isspace()
+                and close_time
+                and not close_time.isspace()
+            ):
+                oh.add_range(item["date"][:2], open_time, close_time)
 
-        yield GeojsonPointItem(**properties)
+        properties["opening_hours"] = oh.as_opening_hours()
 
-    def parse(self, response):
-        urls = response.xpath('//div/div[@class="azsl-panel"]/ul/li/a/@href').extract()
-        for path in urls:
-            yield scrapy.Request(response.urljoin(path), callback=self.parse_stores)
+        yield GeojsonPointItem(**properties)


Test patch: