Repository: alltheplaces/alltheplaces

Issue:
Sunglass Hut (various countries)
### Brand name

Sunglass Hut

### Wikidata ID

Q136311

### Store finder url(s)

https://mena.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:11%20+deleted:false%20+working:true/orderby/modDate%20desc

Covers countries:
* Algeria
* Bahrain
* Cyprus
* Egypt
* Jordan
* KSA
* Kuwait
* Lebanon
* Oman
* Qatar
* UAE

Netherlands: https://nl.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:3%20+deleted:false%20+working:true/orderby/modDate%20desc

Portugal: https://pt.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:4%20+deleted:false%20+working:true/orderby/modDate%20desc

Turkey: https://tr.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:4%20+deleted:false%20+working:true/orderby/modDate%20desc

Hong Kong: https://hk.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:8%20+deleted:false%20+working:true/orderby/modDate%20desc


Discussion:
Hey @davidhicks , I would love to implement this..

Do you want to have a go at writing this spider? I can add it to my TODO list otherwise.
> Do you want to have a go at writing this spider? I can add it to my TODO list otherwise.

Ya, I will have a go at it.

@davidhicks 
[sunglass_hut.py](https://github.com/alltheplaces/alltheplaces/blob/master/locations/spiders/sunglass_hut.py) already exists for AU, CA, GU, NZ, PR, US, VI.
So, Shall I name the one I am implementing as sunglass_hut_it.py?
I think the existing `sunglass_hut` could be renamed to `sunglass_hut_1` and this new spider named `sunglass_hut_2`? I can't see any logical grouping of countries for each spider to be able to suffix with `_europe` or `_apac` or similar.
Note that the countries of [sunglass_hut.py](https://github.com/alltheplaces/alltheplaces/blob/master/locations/spiders/sunglass_hut.py) have their own separate API to the countries referred to in this issue #6003. The other API looks a bit like:
```
https://www.sunglasshut.com/AjaxSGHFindPhysicalStoreLocations?latitude=-37.8152065&longitude=144.963937&radius=100&langId=-26&storeId=11351
```

And you need to change the coordinates and `storeId` to match a location within each country, and then also specify the `radius` differently per country (some countries allow a larger radius than other countries).

I didn't create an issue to switch [sunglass_hut.py](https://github.com/alltheplaces/alltheplaces/blob/master/locations/spiders/sunglass_hut.py) to use the new API. A problem for another day :)
Hey @davidhicks, should the `item["opening_hours"]` be a **string** like `"Mo-Su 10:00-22:00"`  (by applying the [as_opening_hours](https://github.com/alltheplaces/alltheplaces/blob/master/locations/hours.py#L533C20-L533C20) function), or an **OpeningHours  object** like `<locations.hours.OpeningHours object at 0x7ff8347224a0>`?
Thanks.

Resolving patch:
diff --git a/locations/spiders/sunglass_hut.py b/locations/spiders/sunglass_hut_1.py
similarity index 78%
rename from locations/spiders/sunglass_hut.py
rename to locations/spiders/sunglass_hut_1.py
--- a/locations/spiders/sunglass_hut.py
+++ b/locations/spiders/sunglass_hut_1.py
@@ -4,8 +4,8 @@
 
 
 # AU, CA, GU, NZ, PR, US, VI
-class SunglassHutSpider(SitemapSpider, StructuredDataSpider):
-    name = "sunglass_hut"
+class SunglassHut1Spider(SitemapSpider, StructuredDataSpider):
+    name = "sunglass_hut_1"
     item_attributes = {"brand": "Sunglass Hut", "brand_wikidata": "Q136311"}
     allowed_domains = ["stores.sunglasshut.com"]
     sitemap_urls = ["https://stores.sunglasshut.com/robots.txt"]
diff --git a/locations/spiders/sunglass_hut_2.py b/locations/spiders/sunglass_hut_2.py
new file mode 100644
--- /dev/null
+++ b/locations/spiders/sunglass_hut_2.py
@@ -0,0 +1,52 @@
+from scrapy import Spider
+
+from locations.dict_parser import DictParser
+from locations.hours import DAYS_FULL, OpeningHours
+
+
+class SunglassHut2Spider(Spider):
+    name = "sunglass_hut_2"
+    allowed_domains = [
+        "mena.sunglasshut.com",
+        "nl.sunglasshut.com",
+        "pt.sunglasshut.com",
+        "tr.sunglasshut.com",
+        "hk.sunglasshut.com",
+    ]
+
+    item_attributes = {"brand": "Sunglass Hut", "brand_wikidata": "Q136311"}
+
+    start_urls = [
+        "https://mena.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:11%20+deleted:false%20+working:true/orderby/modDate%20desc",
+        "https://nl.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:3%20+deleted:false%20+working:true/orderby/modDate%20desc",
+        "https://pt.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:4%20+deleted:false%20+working:true/orderby/modDate%20desc",
+        "https://tr.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:4%20+deleted:false%20+working:true/orderby/modDate%20desc",
+        "https://hk.sunglasshut.com/api/content/render/false/limit/9999/type/json/query/+contentType:SghStoreLocator%20+languageId:8%20+deleted:false%20+working:true/orderby/modDate%20desc",
+    ]
+
+    def parse(self, response):
+        for data in response.json()["contentlets"]:
+            item = DictParser.parse(data)
+            region = response.url.split("https://", 1)[1].split(".", 1)[0].lower()
+
+            if data["innerCountry"]:
+                item["country"] = data["innerCountry"]
+            else:
+                item["country"] = region.upper()
+                item["country"] = None if (item["country"] == "MENA") else item["country"]
+
+            item["ref"] = f"{region}-{data['seoUrl']}"
+
+            item["website"] = "https://{}.sunglasshut.com/{}/store-locator/{}".format(
+                region, ("en" if region == "mena" else region), data["seoUrl"]
+            )
+
+            item["lat"] = data["geographicCoordinatesLatitude"]
+            item["lon"] = data["geographicCoordinatesLongitude"]
+
+            item["opening_hours"] = OpeningHours()
+            item["opening_hours"].add_ranges_from_string(
+                " ".join(["{}: {}".format(day, data[day.lower()]) for day in DAYS_FULL]), delimiters=[" : "]
+            )
+
+            yield item
diff --git a/locations/spiders/sunglass_hut_gb.py b/locations/spiders/sunglass_hut_gb.py
--- a/locations/spiders/sunglass_hut_gb.py
+++ b/locations/spiders/sunglass_hut_gb.py
@@ -2,13 +2,13 @@
 
 from locations.dict_parser import DictParser
 from locations.hours import OpeningHours
-from locations.spiders.sunglass_hut import SunglassHutSpider
+from locations.spiders.sunglass_hut_1 import SunglassHut1Spider
 from locations.user_agents import BROWSER_DEFAULT
 
 
 class SunglassHutGBSpider(Spider):
     name = "sunglass_hut_gb"
-    item_attributes = SunglassHutSpider.item_attributes
+    item_attributes = SunglassHut1Spider.item_attributes
     start_urls = [
         "https://www.sunglasshut.com/AjaxSGHFindPhysicalStoreLocations?latitude=53.4138458&longitude=-1.782017&radius=1000&storeId=11352"
     ]


Test patch: