Repository: alltheplaces/alltheplaces

Issue:
Fresh Thyme
https://www.freshthyme.com/our-stores/


Discussion:
@iandees I'm working on this

Here's the sample output:

```json
{"type": "Feature", "id": "T0Q3LfXyAcobXTXFNMMtMsPHH_U=", "properties": {"ref": "126", "@spider": "freshthyme", "addr:street": "14727 Fresh Thyme Market Dr.", "addr:city": "Carmel", "addr:state": "IN", "addr:postcode": "46033", "addr:country": "US", "name": "Carmel, IN", "phone": "317-975-7203", "website": "www.freshthyme.com/stores/207", "opening_hours": "Mo-Su 07:00-21:00", "brand": "Fresh Thyme"}, "geometry": {"type": "Point", "coordinates": [-86.10813, 40.00102]}},
{"type": "Feature", "id": "Xgy2YQvsXvpIBTOEJNWNLUjuYjg=", "properties": {"ref": "116", "@spider": "freshthyme", "addr:street": "2500 N. Elston Ave.", "addr:city": "Chicago", "addr:state": "IL", "addr:postcode": "60647", "addr:country": "US", "name": "Chicago, IL - Bucktown", "phone": "872-210-3010", "website": "www.freshthyme.com/stores/107", "opening_hours": "Mo-Su 07:00-22:00", "brand": "Fresh Thyme"}, "geometry": {"type": "Point", "coordinates": [-87.68091, 41.92649]}},
{"type": "Feature", "id": "46YSC02VvvjkJejwFR44XDkpot0=", "properties": {"ref": "135", "@spider": "freshthyme", "addr:street": "11349 Montgomery Rd.", "addr:city": "Cincinnati", "addr:state": "OH", "addr:postcode": "45249", "addr:country": "US", "name": "Cincinnati, OH - Harpers Station", "phone": "513-247-0018", "website": "www.freshthyme.com/stores/304", "opening_hours": "Mo-Su 07:00-21:00", "brand": "Fresh Thyme"}, "geometry": {"type": "Point", "coordinates": [-84.33068, 39.27197]}},
{"type": "Feature", "id": "1Y--cqoVE_rWoQPSRbBCNBH6hkQ=", "properties": {"ref": "185", "@spider": "freshthyme", "addr:street": "1717 Route 228 Ste. E", "addr:city": "Cranberry Township", "addr:state": "PA", "addr:postcode": "16066", "addr:country": "US", "name": "Cranberry Township, PA", "phone": "724 -553 - 7051", "website": "www.freshthyme.com/stores/453", "opening_hours": "Mo-Su 07:00-22:00", "brand": "Fresh Thyme"}, "geometry": {"type": "Point", "coordinates": [-80.0824, 40.68837]}},
```

Resolving patch:
diff --git a/locations/spiders/freshthyme.py b/locations/spiders/freshthyme.py
new file mode 100644
--- /dev/null
+++ b/locations/spiders/freshthyme.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+import json
+
+import scrapy
+from locations.hours import OpeningHours
+from locations.items import GeojsonPointItem
+
+
+class FreshThymeSpider(scrapy.Spider):
+    name = 'freshthyme'
+    item_attributes = {'brand': 'Fresh Thyme'}
+    allowed_domains = ['www.freshthyme.com']
+    start_urls = ['https://discover.freshthyme.com/api/v2/stores']
+
+    def parse(self, response):
+        data = json.loads(response.text)['items']
+        for location in data:
+            hours = location.get('store_hours')
+            address = location.get('address', {})
+            coordinates = location.get('location', {})
+            properties = {
+                'name': location['name'],
+                'ref': location['id'],
+                'street': ', '.join(filter(None, [address.get(f'address{x}') for x in range(1, 4)])),
+                'city': address['city'],
+                'postcode': address['postal_code'],
+                'state': address['province'],
+                'country': 'US',
+                'phone': location['phone_number'],
+                'website': location['external_url'],
+                'lat': float(coordinates['latitude']),
+                'lon': float(coordinates['longitude']),
+                'opening_hours': self.parse_hours(hours) if hours else None
+            }
+            yield GeojsonPointItem(**properties)
+
+    def parse_hours(self, store_hours):
+        opening_hours = OpeningHours()
+
+        for weekday in store_hours:
+            day = weekday.title()
+            interval = store_hours[weekday]
+            if isinstance(interval, dict):                   
+                open_time = str(interval.get("start"))
+                close_time = str(interval.get("end"))
+                opening_hours.add_range(day=day[:2],
+                                        open_time=open_time,
+                                        close_time=close_time,
+                                        time_format='%H:%M:%S')
+        return opening_hours.as_opening_hours()


Test patch: