Repository: alltheplaces/alltheplaces

Issue:
Quality Inn



Discussion:
@iandees I am not familiar with Quality Inn, Google search points to https://www.choicehotels.com
can you confirm this URL? 

-edited-, more stories now being added.
Thanks.
Yes, it looks like Quality Inn is part of Choice Hotels.
This issue hasn't been worked on in a while. I'm removing the assignment so others can work on it. If you're still working on it, please reassign yourself and reference a pull request or branch where you're doing your work.

Resolving patch:
diff --git a/locations/spiders/choicehotels.py b/locations/spiders/choicehotels.py
new file mode 100644
--- /dev/null
+++ b/locations/spiders/choicehotels.py
@@ -0,0 +1,76 @@
+import json
+import re
+import scrapy
+
+from locations.items import GeojsonPointItem
+
+
+brand_name_override = {
+    'Comfort Suites Suites': 'Comfort Suites',
+    'Econo Lodge Lodge': 'Econo Lodge'
+}
+
+
+class ChoiceHotelsSpider(scrapy.Spider):
+    name = "choicehotels"
+    allowed_domains = ["choicehotels.com"]
+    download_delay = 0.2
+
+    base_url = 'https://www.choicehotels.com/cms/pages/choice-hotels'
+
+    start_urls = [
+        'https://www.choicehotels.com/cms/pages/comfort-inn/sitemap?d=DESKTOP&applocale=en-us',
+        'https://www.choicehotels.com/cms/pages/comfort-suites/sitemap?d=DESKTOP&applocale=en-u',
+        'https://www.choicehotels.com/cms/pages/quality-inn/sitemap?d=DESKTOP&applocale=en-u',
+        'https://www.choicehotels.com/cms/pages/sleep-inn/sitemap?d=DESKTOP&applocale=en-u',
+        'https://www.choicehotels.com/cms/pages/clarion/sitemap?d=DESKTOP&applocale=en-u',
+        'https://www.choicehotels.com/cms/pages/cambria/sitemap?d=DESKTOP&applocale=en-u',
+        'https://www.choicehotels.com/cms/pages/mainstay/sitemap?d=DESKTOP&applocale=en-u',
+        'https://www.choicehotels.com/cms/pages/suburban/sitemap?d=DESKTOP&applocale=en-u',
+        'https://www.choicehotels.com/cms/pages/econo-lodge/sitemap?d=DESKTOP&applocale=en-u',
+        'https://www.choicehotels.com/cms/pages/rodeway-inn/sitemap?d=DESKTOP&applocale=en-u',
+    ]
+
+    def parse_hotel(self, response):
+        script = "".join(response.xpath('//script/text()').extract())
+        data = json.loads(re.search(r'window.hotelInfoData = (.*)?;', script).group(1))
+
+        if data["hotel"]["status"] == "TERMINATED":
+            return
+
+        brand = data["hotel"]["general"]["brandName"] + " " + data["hotel"]["general"]["productName"]
+
+        properties = {
+            'ref': data["hotel"]["id"],
+            'name': data["hotel"]["name"],
+            'addr_full':  data["hotel"]["address"]["line1"],
+            'city':  data["hotel"]["address"]["city"],
+            'state':  data["hotel"]["address"].get("subdivision"),
+            'postcode':  data["hotel"]["address"].get("postalCode"),
+            'country':  data["hotel"]["address"]["country"],
+            'phone': data["hotel"]["general"]["phone"],
+            'lat': float(data["hotel"]["general"]["lat"]),
+            'lon': float(data["hotel"]["general"]["lon"]),
+            'website': response.url,
+            'extras': {
+                'brand': brand_name_override.get(brand, brand)
+            }
+        }
+
+        yield GeojsonPointItem(**properties)
+
+    def parse_hotel_list(self, response):
+        urls = response.xpath('//p/a/@href').extract()
+        if not urls:
+            urls = response.xpath('//div/a/@href').extract()
+
+        for url in urls:
+            yield scrapy.Request(response.urljoin(url), callback=self.parse_hotel)
+
+    def parse(self, response):
+        urls = response.xpath('//h3[contains(text(), "Locations")]/following-sibling::div//h6/a/@href').extract()
+
+        for url in urls:
+            yield scrapy.Request(self.base_url + url, callback=self.parse_hotel_list)
+
+


Test patch: