Repository: alltheplaces/alltheplaces

Issue:
Loblaws & Superstore & Thirfty Foods & Fairway's Market & Safeway & Save on Foods & Farmboy
- [x] [Loblaws](https://www.loblaws.ca/store-locator)
- [x] [Superstore](https://www.realcanadiansuperstore.ca/store-locator)
- [x] [Thrifty Foods](https://www.thriftyfoods.com/find-a-store)
- [x] [Fairways](http://www.fairwaymarkets.com/index.php/store-locations)
- [x] [Safeway](https://www.safeway.ca/find-a-store) #311
- [x] [Save on Foods](https://shop.saveonfoods.com/chain/8E4E398?hash=locator&_ga=1.168908327.789228674.1484454975)
- [x] [Farm Boy](https://www.farmboy.ca/about-us/stores/)




Discussion:
I can work on this.
Going to clear the assignee on this so others can work on it. If you're still working on it, please re-assign to yourself and push up what you've got so far.
These should all be broken out into their own tickets. A lot of them have already been done.
working on this.
@iandees , I think this issue should be opened for other stores.
Thanks.

Resolving patch:
diff --git a/locations/spiders/fairway_market.py b/locations/spiders/fairway_market.py
new file mode 100644
--- /dev/null
+++ b/locations/spiders/fairway_market.py
@@ -0,0 +1,76 @@
+# -*- coding: utf-8 -*-
+import scrapy
+import re
+
+from locations.items import GeojsonPointItem
+
+
+class FairwayMarketSpider(scrapy.Spider):
+    name = "fairway_market"
+    allowed_domains = ["http://www.fairwaymarkets.com/"]
+    start_urls = (
+        'http://www.fairwaymarkets.com/index.php/store-locations/victoria',
+        'http://www.fairwaymarkets.com/index.php/store-locations/sidney',
+        'http://www.fairwaymarkets.com/index.php/store-locations/brentwood',
+        'http://www.fairwaymarkets.com/index.php/store-locations/nanaimo',
+    )
+    
+
+    def parse(self, response):
+        data = response.xpath('//div[@class="art-content-wide"]')
+        for store in data.xpath('.//div[@class="art-Post-inner"]'):
+
+            properties = {
+                "ref": store.xpath('div[@class="art-PostContent"]/div[@class="art-article"]/p/text()').extract_first(),
+                "addr_full": store.xpath('div[@class="art-PostContent"]/div[@class="art-article"]/p/text()').extract_first(),
+                "name": store.xpath('h2/span[@class="art-PostHeader"]/text()').extract_first().replace('\n',''),
+                "city": self.city(store.xpath('div[@class="art-PostContent"]/div[@class="art-article"]/p/text()')[1].extract()),
+                "state": self.state(store.xpath('div[@class="art-PostContent"]/div[@class="art-article"]/p/text()')[1].extract()),
+                "postcode": store.xpath('div[@class="art-PostContent"]/div[@class="art-article"]/p/text()')[2].extract(),
+                "opening_hours": self.store_hours(store.xpath('div[@class="art-PostContent"]/div[@class="art-article"]/p/strong/text()').extract_first()),
+                # "lon": float(store.xpath('longitude/text()').extract_first()),
+                # "lat": float(store.xpath('latitude/text()').extract_first()),
+            }
+
+
+            yield GeojsonPointItem(**properties)
+        else:
+            self.logger.info("No results")
+
+    def city(self, data):
+        str_list = data.split(',')
+        return str_list[0].strip()
+
+    def state(self, data):
+        str_list = data.split(',')
+        state = str_list[1].strip()
+        return state
+
+
+    def store_hours(self, store_hours):
+        if "day" not in store_hours and "-" not in store_hours:
+            return ""
+        days = 'Mo-Su'
+        hours = ''
+        match = re.search(r'(\d{1,2})(A|P)M to (\d{1,2})(A|P)M', store_hours)
+        if match:
+            (f_hr, f_ampm, t_hr, t_ampm) = match.groups()
+            f_hr = int(f_hr)
+            if f_ampm == 'P':
+                f_hr += 12
+            elif f_ampm == 'A' and f_hr == 12:
+                f_hr = 0
+            t_hr = int(t_hr)
+            if t_ampm == 'P':
+                t_hr += 12
+            elif t_ampm == 'A' and t_hr == 12:
+                t_hr = 0
+            
+            hours = '{:02d}:{}-{:02d}:{}'.format(
+                f_hr,
+                '00',
+                t_hr,
+                '00',
+            )
+
+        return days + ' ' + hours


Test patch: