Repository: alltheplaces/alltheplaces

Issue:
Jim 'N Nick's BBQ
https://www.jimnnicks.com/locations/


Discussion:

Resolving patch:
diff --git a/locations/spiders/churchs_chicken.py b/locations/spiders/churchs_chicken.py
--- a/locations/spiders/churchs_chicken.py
+++ b/locations/spiders/churchs_chicken.py
@@ -11,7 +11,7 @@ class ChurchsChickenSpider(scrapy.Spider):
 
     def parse_store(self, response):
         if response.url == "https://locations.churchs.com/index.html":
-            return # not found, redirects
+            return  # not found, redirects
 
         ref = re.search(r".*\/([0-9]+[a-z\-]+)", response.url).group(1)
         name = response.xpath(
diff --git a/locations/spiders/jim_n_nicks_bbq.py b/locations/spiders/jim_n_nicks_bbq.py
new file mode 100644
--- /dev/null
+++ b/locations/spiders/jim_n_nicks_bbq.py
@@ -0,0 +1,50 @@
+import re
+import scrapy
+from locations.items import GeojsonPointItem
+
+
+class JimNNicksBBQSpider(scrapy.Spider):
+    name = "jim_n_nicks"
+    allowed_domains = ["www.jimnnicks.com"]
+    item_attributes = {"brand": "Jim 'N Nick's"}
+    start_urls = ("https://www.jimnnicks.com/locations/",)
+
+    def parse(self, response):
+        urls = response.xpath('//ul[@class="directory-links"]/li/a/@href').extract()
+
+        for url in urls:
+            if url.count("/") >= 6:
+                yield scrapy.Request(url, self.parse_location)
+            else:
+                yield scrapy.Request(url)
+
+    def parse_location(self, response):
+        is_actually_store_list = response.xpath(
+            '//ul[@class="directory-links"]/li/a/@href'
+        ).extract()
+
+        if is_actually_store_list:
+            for url in is_actually_store_list:
+                yield scrapy.Request(url, self.parse_location)
+        else:  # Collect the data
+            ref = re.search(r".+/(.+?)/?(?:\.html|$)", response.url).group(1)
+            complete_address = response.xpath("//address/text()").extract()
+            street_address = complete_address[0]
+            city, state_postal = complete_address[-1].split(",")
+            state, postal = state_postal.strip().split()
+
+            properties = {
+                "ref": ref,
+                "name": response.xpath("//h1/text()").extract_first().strip(),
+                "addr_full": street_address,
+                "city": city,
+                "state": state,
+                "postcode": postal,
+                "country": "US",
+                "phone": response.xpath(
+                    '//div[@class="elementor-shortcode"]/a/text()[1]'
+                ).extract_first(),
+                "website": response.url,
+            }
+
+            yield GeojsonPointItem(**properties)
diff --git a/locations/spiders/vallarta.py b/locations/spiders/vallarta.py
--- a/locations/spiders/vallarta.py
+++ b/locations/spiders/vallarta.py
@@ -17,30 +17,34 @@ def parse(self, response):
         for url in urls:
             if url == "https://vallartasupermarkets.com/store-locations/":
                 continue
-            yield scrapy.Request(
-                url=url, callback=self.parse_store, meta={"url": url}
-            )
+            yield scrapy.Request(url=url, callback=self.parse_store, meta={"url": url})
 
     def parse_store(self, response):
 
-        address = (
-            response.xpath("//div[@class='blade store-location']/div/div/div[2]/p[1]/text()").extract()
-        )
+        address = response.xpath(
+            "//div[@class='blade store-location']/div/div/div[2]/p[1]/text()"
+        ).extract()
 
         # No lat/lon in source code; Google map link contains address
         yield GeojsonPointItem(
             ref=response.url.split("/")[-2],
-            name=response.xpath("//div[@class='page-breadcrumb']/span/text()").extract_first(),
+            name=response.xpath(
+                "//div[@class='page-breadcrumb']/span/text()"
+            ).extract_first(),
             addr_full=address[1].strip(),
-            city=address[2].split(',')[0].strip(),
-            state=address[2].split(' ')[-2].strip(),
-            postcode=address[2].split(' ')[-1].strip(),
+            city=address[2].split(",")[0].strip(),
+            state=address[2].split(" ")[-2].strip(),
+            postcode=address[2].split(" ")[-1].strip(),
             country="United States",
             phone=response.xpath("//a[@class='tel']/text()").extract_first().strip(),
             website=response.url,
             opening_hours=self.parse_hours(
-                response.xpath("//div[contains(@class, 'days')]/text()").extract_first().strip(),
-                response.xpath("//div[contains(@class, 'hours')]//p/text()").extract_first().strip()
+                response.xpath("//div[contains(@class, 'days')]/text()")
+                .extract_first()
+                .strip(),
+                response.xpath("//div[contains(@class, 'hours')]//p/text()")
+                .extract_first()
+                .strip(),
             ),
         )
 


Test patch: