Repository: alltheplaces/alltheplaces

Issue:
Supercor (ES) (JS Blob)

### Brand name

Supercor

### Wikidata ID

Q6135841
https://www.wikidata.org/wiki/Q6135841
https://www.wikidata.org/wiki/Special:EntityData/Q6135841.json

### Store finder url(s)
https://www.supercor.es/tiendas/
Official Url(s): http://www.supercor.es
- [x] I have run the below and if anything in generated, added it.
- [x] I have manually checked for a storefinder
- [ ] This is not a manufacturer listing outlets operating under their own brands / this will not create duplicates
`pipenv run scrapy sf --brand-wikidata=Q6135841 http://www.supercor.es`
```
```



Discussion:
<html>
<body>
<!--StartFragment-->
var tiendas = `[{"name":"Supercor","direccion":"Av. de Diego Mart\u00ednez Barrio, 4, 41013 Sevilla, Espa\u00f1a","categoria":"supermercados","coordenadax":"37.37608","coordenaday":"-5.9761048","ciudad":"Sevilla","cp"
--


<!--EndFragment-->
</body>
</html>

Resolving patch:
diff --git a/locations/dict_parser.py b/locations/dict_parser.py
--- a/locations/dict_parser.py
+++ b/locations/dict_parser.py
@@ -6,6 +6,7 @@ class DictParser:
     # the common variants of case including such acronyms need to
     # all be listed below.
     ref_keys = [
+        # EN
         "ref",
         "id",
         "identifier",
@@ -25,9 +26,36 @@ class DictParser:
         "itemID",
     ]
 
-    name_keys = ["name", "store-name", "display-name", "title", "business-name", "item-name", "location-name"]
+    name_keys = [
+        # EN
+        "name",
+        "store-name",
+        "display-name",
+        "title",
+        "business-name",
+        "item-name",
+        "location-name",
+    ]
 
-    house_number_keys = ["house-number", "house-no", "street-number", "street-no", "address-street-no"]
+    house_number_keys = [
+        # EN
+        "house-number",
+        "house-no",
+        "street-number",
+        "street-no",
+        "address-street-no",
+    ]
+
+    full_address_keys = [
+        # EN
+        "address",
+        "addr",
+        "store-address",
+        "physical-address",
+        "full-address",
+        # ES
+        "direccion",  # "address"
+    ]
 
     street_address_keys = [
         # EN
@@ -54,6 +82,8 @@ class DictParser:
         "市区町村",  # "municipality"
         # PL
         "miasto",
+        # ES
+        "ciudad",  # "city"
     ]
 
     region_keys = [
@@ -72,6 +102,7 @@ class DictParser:
     ]
 
     country_keys = [
+        # EN
         "country-code",
         "address-country",
         "country",
@@ -104,9 +135,17 @@ class DictParser:
         "郵便番号",  # "post code"
     ]
 
-    email_keys = ["email", "contact-email", "email-address", "email1", "store-email"]
+    email_keys = [
+        # EN
+        "email",
+        "contact-email",
+        "email-address",
+        "email1",
+        "store-email",
+    ]
 
     phone_keys = [
+        # EN
         "phone-number",
         "phone",
         "telephone",
@@ -118,9 +157,12 @@ class DictParser:
         "contact-phone",
         "store-phone",
         "primary-phone",
+        # ES
+        "telefono",  # "phone"
     ]
 
     lat_keys = [
+        # EN
         "latitude",
         "lat",
         "store-latitude",
@@ -128,9 +170,12 @@ class DictParser:
         "yext-display-lat",
         "map-latitude",
         "geo-lat",
+        # ES
+        "coordenaday",  # "Coordinate Y"
     ]
 
     lon_keys = [
+        # EN
         "longitude",
         "lon",
         "long",
@@ -140,9 +185,20 @@ class DictParser:
         "yext-display-lng",
         "map-longitude",
         "geo-lng",
+        # ES
+        "coordenadax",  # "Coordinate X"
     ]
 
-    website_keys = ["url", "website", "permalink", "store-url", "storeURL", "website-url", "websiteURL"]
+    website_keys = [
+        # EN
+        "url",
+        "website",
+        "permalink",
+        "store-url",
+        "storeURL",
+        "website-url",
+        "websiteURL",
+    ]
 
     @staticmethod
     def parse(obj) -> Feature:
@@ -170,9 +226,7 @@ def parse(obj) -> Feature:
         item["lat"] = DictParser.get_first_key(location, DictParser.lat_keys)
         item["lon"] = DictParser.get_first_key(location, DictParser.lon_keys)
 
-        address = DictParser.get_first_key(
-            obj, ["address", "addr", "store-address", "physical-address", "full-address"]
-        )
+        address = DictParser.get_first_key(obj, DictParser.full_address_keys)
 
         if address and isinstance(address, str):
             item["addr_full"] = address
diff --git a/locations/spiders/supercor_es.py b/locations/spiders/supercor_es.py
new file mode 100644
--- /dev/null
+++ b/locations/spiders/supercor_es.py
@@ -0,0 +1,36 @@
+from hashlib import sha1
+
+from chompjs import parse_js_object
+from scrapy import Spider
+
+from locations.categories import Categories
+from locations.dict_parser import DictParser
+from locations.hours import DAYS_ES, OpeningHours
+
+
+class SupercorESSpider(Spider):
+    name = "supercor_es"
+    item_attributes = {"brand": "Supercor", "brand_wikidata": "Q6135841", "extras": Categories.SHOP_SUPERMARKET.value}
+    allowed_domains = ["www.supercor.es"]
+    start_urls = ["https://www.supercor.es/tiendas/"]
+
+    def parse(self, response):
+        js_blob = response.xpath('//script[contains(text(), "var tiendas = `")]/text()').get()
+        js_blob = js_blob.split("var tiendas = `", 1)[1].split("`;", 1)[0]
+        locations = parse_js_object(js_blob, unicode_escape=True)
+        for location in locations:
+            # Ignore closed stores
+            if location["abierto"] != "1":
+                continue
+
+            item = DictParser.parse(location)
+            # Create a reference ID from the store address as this is the most
+            # permanent identifier available to be used.
+            item["ref"] = sha1(location["direccion"].encode("UTF-8")).hexdigest()
+            item["postcode"] = location["cp"]
+
+            hours_text = " ".join(location["horario"]).replace(":|", ": ")
+            item["opening_hours"] = OpeningHours()
+            item["opening_hours"].add_ranges_from_string(hours_text, days=DAYS_ES)
+
+            yield item


Test patch: