Repository: alltheplaces/alltheplaces

Issue:
Spider steak_n_shake is broken
During the global build at 2021-07-14-14-42-22, spider **steak_n_shake** failed with **0 features** and **1 errors**.

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


Discussion:
During the global build at 2021-08-25-14-42-15, spider **steak_n_shake** failed with **0 features** and **1 errors**.

Here's [the log](https://data.alltheplaces.xyz/runs/2021-08-25-14-42-15/logs/steak_n_shake.txt) and [the output](https://data.alltheplaces.xyz/runs/2021-08-25-14-42-15/output/steak_n_shake.geojson) ([on a map](https://data.alltheplaces.xyz/map.html?show=https://data.alltheplaces.xyz/runs/2021-08-25-14-42-15/output/steak_n_shake.geojson))

Resolving patch:
diff --git a/locations/spiders/steak_n_shake.py b/locations/spiders/steak_n_shake.py
--- a/locations/spiders/steak_n_shake.py
+++ b/locations/spiders/steak_n_shake.py
@@ -1,134 +1,74 @@
 # -*- coding: utf-8 -*-
+import json
+
 import scrapy
+
 from locations.items import GeojsonPointItem
-import json
 
-daysKey = {
-    'Mon': 'Mo', 'Tue': 'Tu', 'Wed': 'We', 'Thur': 'Th',
-    'Fri': 'Fr', 'Sat': 'Sa', 'Sun': 'Su'
-}
+
+
 
 class SteakNShakeSpider(scrapy.Spider):
     name = "steak_n_shake"
-    item_attributes = { 'brand': "Steak N Shake" }
+    item_attributes = {'brand': "Steak N Shake", 'brand_wikidata': "Q7605233"}
     allowed_domains = ["www.steaknshake.com"]
     start_urls = (
-        'https://www.steaknshake.com/zsapi/locations/',
+        'https://www.steaknshake.com/locations/',
     )
 
-    def parse_hours(self, hours):
-        days = hours.split(': ')[0].strip()
-        bothHours = hours.split(': ')[1].strip()
-
-        if('-' in days):
-            startDay = daysKey[days.split('-')[0].strip()]
-            endDay = daysKey[days.split('-')[1].strip()]
-            dayOutput = startDay + "-" + endDay
-        else:
-            dayOutput = daysKey[days]
-
-        if("Closed" in bothHours):
-            return ""
-        if("24 hours" in bothHours):
-            return dayOutput + ": 00:00-24:00; "
-
-
-        openHours = bothHours.split("-")[0]
-        closeHours = bothHours.split("-")[1]
-
-        if("am" in openHours):
-            openHours = openHours.replace("am","")
-            if(":" in openHours):
-                openH = openHours.split(":")[0]
-                openM = openHours.split(":")[1]
-            else:
-                openH = openHours
-                openM = "00"
-            openHours = openH.strip() + ":" + openM.strip()
 
-        if("pm" in openHours):
-            openHours = openHours.replace("pm","")
-            if(":" in openHours):
-                openH = openHours.split(":")[0]
-                openM = openHours.split(":")[1]
-            else:
-                openH = openHours
-                openM = "00"
-            openH = str(int(openH) + 12)
-            openHours = openH.strip() + ":" + openM.strip()
-
-        if("am" in closeHours):
-            closeHours = closeHours.replace("am","")
-            if(":" in closeHours):
-                closeH = closeHours.split(":")[0]
-                closeM = closeHours.split(":")[1]
-            else:
-                closeH = closeHours
-                closeM = "00"
-            closeHours = closeH.strip() + ":" + closeM.strip()
-
-        if("pm" in closeHours):
-            closeHours = closeHours.replace("pm","")
-            if(":" in closeHours):
-                closeH = closeHours.split(":")[0]
-                closeM = closeHours.split(":")[1]
-            else:
-                closeH = closeHours
-                closeM = "00"
-            closeH = str(int(closeH) + 12)
-            closeHours = closeH.strip() + ":" + closeM.strip()
-
-        return dayOutput +' '+ openHours.replace(' ','') + "-" + closeHours + '; '
+    def start_requests(self):
+        url = "https://www.steaknshake.com/wp-admin/admin-ajax.php"
+
+        formdata = {
+            'action': "get_location_data_from_plugin"
+            }
+
+        headers = {
+            'Host': 'www.steaknshake.com',
+            'Connection': 'keep - alive',
+            'Content - Length': '36',
+            'sec - ch - ua': ' "Chromium";v="94", "Google Chrome";v="94", ";Not A Brand";v="99"',
+            'Accept': '* / *',
+            'Content - Type': ' application/x-www-form-urlencoded; charset=UTF-8',
+            'X - Requested - With': 'XMLHttpRequest',
+            'sec - ch - ua - mobile': '?0',
+            'User - Agent': ' Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.71 Safari/537.36',
+            'sec - ch - ua - platform': '"macOS"',
+            'Origin': 'https: // www.steaknshake.com',
+            'Sec - Fetch - Site': 'same - origin',
+            'Sec - Fetch - Mode': 'cors',
+            'Sec - Fetch - Dest': 'empty',
+            'Referer': 'https: // www.steaknshake.com / locations /?q = 78704',
+            'Accept - Encoding': 'gzip, deflate, br',
+            'Accept - Language': ' en-US,en;q=0.9',
+            'Cookie': ' _gcl_au=1.1.2003816794.1633380447; _ga=GA1.2.113267977.1633380448; _gid=GA1.2.33610528.1633380448; rewardspopup=visited; _gat_UA-41904139-5=1; _fbp=fb.1.1633442235013.1462044292'
+            }
+
+        yield scrapy.http.FormRequest(
+            url=url,
+            method="POST",
+            headers=headers,
+            formdata=formdata,
+            callback=self.parse)
 
     def parse(self, response):
-        json_string = json.loads(response.xpath("./body/p/text()").extract_first())
-        for item in json_string:
-
-            openingHoursString=""
-
-            try:
-                for s in item["hours"]["sets"][0]["hours"]:
-                    if("," in item["hours"]["sets"][0]["hours"][s]):
-                        for e in item["hours"]["sets"][0]["hours"][s].split(','):
-                            unformattedData = s + ": " + e
-                            openingHoursString = openingHoursString + self.parse_hours(unformattedData) 
-                    else:
-                        unformattedData = s + ": " + item["hours"]["sets"][0]["hours"][s]
-                        openingHoursString = openingHoursString + self.parse_hours(unformattedData)
-            except IndexError:
-                openingHoursString = ""
-
-            try:
-                latFloat=item["address"]["loc"][1]
-                lonFloat=item["address"]["loc"][0]
-            except KeyError:
-                latFloat=None
-                lonFloat=None
-
-            try:
-                phoneString = item["phone1"].replace('-','')
-            except KeyError:
-                phoneString=None
-
-            try:
-                address2 = item["address"]["address2"]
-            except KeyError:
-                address2 = ""
-
-            address = item["address"]["address1"] + " " + address2
-            address = address.strip()
-
-            yield GeojsonPointItem(
-                ref=item["id"],
-                name=item["name"],
-                opening_hours=openingHoursString.strip(),
-                addr_full=address,
-                city=item["address"]["city"],
-                state=item["address"]["region"],
-                postcode=item["address"]["zip"],
-                phone=phoneString,
-                country=item["address"]["country"],
-                lat=latFloat,
-                lon=lonFloat,
-            )
-
+        jsonresponse = json.loads(response.body_as_unicode())
+        for stores in jsonresponse:
+            store = json.dumps(stores)
+            store_data = json.loads(store)
+
+            properties = {
+                'ref': store_data["brandChainId"],
+                'name': store_data["slug"],
+                'addr_full': store_data["address"]["address1"],
+                'city': store_data["address"]["city"],
+                'state': store_data["address"]["region"],
+                'postcode': store_data["address"]["zip"],
+                'country': store_data["address"]["country"],
+                'phone': store_data["phone1"],
+                'lat': store_data["address"]["loc"][1],
+                'lon': store_data["address"]["loc"][0],
+                'website': response.url
+            }
+            yield GeojsonPointItem(**properties)
\ No newline at end of file


Test patch: