We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Spider wyndham is broken
During the global build at 2021-10-20-14-42-48, spider **wyndham** failed with **116 features** and **1 errors**.

Here's [the log](https://data.alltheplaces.xyz/runs/2021-10-20-14-42-48/logs/wyndham.txt) and [the output](https://data.alltheplaces.xyz/runs/2021-10-20-14-42-48/output/wyndham.geojson) ([on a map](https://data.alltheplaces.xyz/map.html?show=https://data.alltheplaces.xyz/runs/2021-10-20-14-42-48/output/wyndham.geojson))

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `locations/spiders/wyndham.py`
Content:
```
1 # -*- coding: utf-8 -*-
2 import json
3 import re
4 import scrapy
5 from locations.items import GeojsonPointItem
6 
7 BRAND_MAP = {
8     "hj": "hojo",
9     "HJ": "hojo",
10     "hojo": "HJ",
11     "lq": "laquinta",
12     "LQ": "laquinta",
13     "laquinta": "LQ",
14     "di": "days-inn",
15     "DI": "days-inn",
16     "days-inn": "DI",
17     "bh": "hawthorn-extended-stay",
18     "BH": "hawthorn-extended-stay",
19     "hawthorn-extended-stay": "BH",
20     "hr": "wyndham",
21     "HR": "wyndham",
22     "wyndham": "HR",
23     "wg": "wingate",
24     "WG": "wingate",
25     "wingate": "WG",
26     "se": "super-8",
27     "SE": "super-8",
28     "super-8": "SE",
29     "bu": "baymont",
30     "BU": "baymont",
31     "baymont": "BU",
32     "dx": "dolce",
33     "DX": "dolce",
34     "dolce": "DX",
35     "dz": "dazzler",
36     "DZ": "dazzler",
37     "dazzler": "DZ",
38     "wr": "wyndham-rewards",
39     "WR": "wyndham-rewards",
40     "wyndham-rewards": "WR",
41     "kg": "knights-inn",
42     "KG": "knights-inn",
43     "knights-inn": "KG",
44     "wt": "tryp",
45     "WT": "tryp",
46     "tryp": "WT",
47     "aa": "americinn",
48     "AA": "americinn",
49     "americinn": "AA",
50     "all": "wyndham-hotel-group",
51     "ALL": "wyndham-hotel-group",
52     "wyndham-hotel-group": "ALL",
53     "ce": "caesars-entertainment",
54     "CE": "caesars-entertainment",
55     "caesars-entertainment": "CE",
56     "mt": "microtel",
57     "MT": "microtel",
58     "microtel": "MT",
59     "gn": "wyndham-garden",
60     "GN": "wyndham-garden",
61     "wyndham-garden": "GN",
62     "gr": "wyndham-grand",
63     "GR": "wyndham-grand",
64     "wyndham-grand": "GR",
65     "es": "esplendor",
66     "ES": "esplendor",
67     "esplendor": "ES",
68     "ra": "ramada",
69     "RA": "ramada",
70     "ramada": "RA",
71     "re": "registry-collection",
72     "RE": "registry-collection",
73     "registry-collection": "RE",
74     "tl": "travelodge",
75     "TL": "travelodge",
76     "travelodge": "TL",
77     "vo": "wyndham-vacations",
78     "VO": "wyndham-vacations",
79     "wyndham-vacations": "VO",
80     "tq": "trademark",
81     "TQ": "trademark",
82     "trademark": "TQ",
83 }
84 BRAND_TIER_MAP = {"hr": "wy", "gr": "wy", "gn": "wy", "dz": "fe", "es": "fe"}
85 COUNTRIES = {
86     "Canada": "CA",
87     "Turkey": "TR",
88     "United States": "US",
89     "Mexico": "MX",
90     "Honduras": "HN",
91     "Chile": "CL",
92     "Colombia": "CO",
93 }
94 HEADERS = {
95     "Host": "www.wyndhamhotels.com",
96     "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0",
97     "Accept": "*/*",
98     "Accept-Language": "en-US,en;q=0.5",
99     "Accept-Encoding": "gzip, deflate, br",
100     "X-Requested-With": "XMLHttpRequest",
101     "DNT": "1",
102     "Connection": "keep-alive",
103     "Referer": "https://www.wyndhamhotels.com/locations",
104     "TE": "Trailers",
105 }
106 
107 
108 
109 def create_url(brand, city, state, unique_url, tier_id):
110     # In the html, there is a script which this recreates
111     brand_name = BRAND_MAP.get(brand)
112     if not brand_name:
113         brand_name = BRAND_MAP.get(tier_id.lower())
114     url = brand_name + "/"
115     url += city.replace(" ", "-").replace(".","").lower()
116     state_name = (
117         f"-{state.replace(' ','-').lower()}"
118         if state.lower() != "other than us/canada"
119         else ""
120     )
121     url += state_name + "/"
122     url += unique_url.lower() + "/"
123     url += "overview"
124     return url
125 
126 
127 class WyndhamSpider(scrapy.Spider):
128     name = "wyndham"
129     allowed_domains = ["www.wyndhamhotels.com"]
130     headers = HEADERS
131 
132     def start_requests(self):
133         start_url = "https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=&pageNumber=1&brandId=ALL&countryCode=&noPropertyData=false"
134         yield scrapy.Request(start_url, callback=self.parse, headers=self.headers)
135 
136     def parse(self, response):
137         data = json.loads(response.text)
138         for country in data["countries"]:
139             country_code = country["countryCode"]
140             for state in country["states"]:
141                 state_name = state["stateName"]
142                 for city in state["cities"]:
143                     city_name = city["cityName"]
144                     for property_ in city["propertyList"]:
145                         property_id = property_["propertyId"]
146                         brand_id = property_["brandId"]
147                         brand_name = property_["brand"]
148                         brand_tier = property_["tierId"]
149                         unique_url = property_["uniqueUrl"]
150                         url = create_url(
151                             brand_id, city_name, state_name, unique_url, brand_tier
152                         )
153                         yield scrapy.Request(
154                             f"https://{self.allowed_domains[0]}/{url}",
155                             self.parse_property,
156                             meta={
157                                 "id": property_id,
158                                 "country_code": country_code,
159                                 "brand_name": brand_name,
160                             },
161                             headers=HEADERS,
162                         )
163 
164     def parse_property(self, response):
165         raw_json = re.search(
166             r'<script type="application\/ld\+json"\>(.+?)\<',
167             response.text,
168             flags=re.DOTALL,
169         )
170         if not raw_json:
171             return None
172         data = json.loads(raw_json.group(1).replace("\t"," "))
173         properties = {
174             "ref": response.meta["id"],
175             "lat": data["geo"]["latitude"],
176             "lon": data["geo"]["longitude"],
177             "name": data["name"],
178             "addr_full": data["address"]["streetAddress"],
179             "city": data["address"]["addressLocality"],
180             "state": data["address"].get("addressRegion"),
181             "postcode": data["address"].get("postalCode"),
182             "country": response.meta["country_code"],
183             "phone": data["telephone"],
184             "website": response.url,
185             "brand": response.meta["brand_name"],
186         }
187         yield GeojsonPointItem(**properties)
188
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/locations/spiders/wyndham.py b/locations/spiders/wyndham.py
--- a/locations/spiders/wyndham.py
+++ b/locations/spiders/wyndham.py
@@ -3,6 +3,7 @@
 import re
 import scrapy
 from locations.items import GeojsonPointItem
+from urllib.parse import urlparse, parse_qs
 
 BRAND_MAP = {
     "hj": "hojo",
@@ -91,19 +92,6 @@
     "Chile": "CL",
     "Colombia": "CO",
 }
-HEADERS = {
-    "Host": "www.wyndhamhotels.com",
-    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0",
-    "Accept": "*/*",
-    "Accept-Language": "en-US,en;q=0.5",
-    "Accept-Encoding": "gzip, deflate, br",
-    "X-Requested-With": "XMLHttpRequest",
-    "DNT": "1",
-    "Connection": "keep-alive",
-    "Referer": "https://www.wyndhamhotels.com/locations",
-    "TE": "Trailers",
-}
-
 
 
 def create_url(brand, city, state, unique_url, tier_id):
@@ -126,15 +114,25 @@
 
 class WyndhamSpider(scrapy.Spider):
     name = "wyndham"
+    download_speed = 0.7
     allowed_domains = ["www.wyndhamhotels.com"]
-    headers = HEADERS
-
-    def start_requests(self):
-        start_url = "https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=&pageNumber=1&brandId=ALL&countryCode=&noPropertyData=false"
-        yield scrapy.Request(start_url, callback=self.parse, headers=self.headers)
+    start_urls = (
+        'https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=50&pageNumber=1&brandId=ALL&countryCode=US%2CCA%2CMX',
+    )
 
     def parse(self, response):
         data = json.loads(response.text)
+
+        page_count = data.get('pageCount')
+        parsed_url = urlparse(response.request.url)
+        parsed_args = parse_qs(parsed_url.query)
+        page_number = int(parsed_args['pageNumber'][0])
+        if page_number <= page_count:
+            next_page_number = page_number + 1
+            yield scrapy.Request(
+                f'https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=50&pageNumber={next_page_number}&brandId=ALL&countryCode=US%2CCA%2CMX',
+            )
+
         for country in data["countries"]:
             country_code = country["countryCode"]
             for state in country["states"]:
@@ -158,7 +156,6 @@
                                 "country_code": country_code,
                                 "brand_name": brand_name,
                             },
-                            headers=HEADERS,
                         )
 
     def parse_property(self, response):

{"golden_diff": "diff --git a/locations/spiders/wyndham.py b/locations/spiders/wyndham.py\n--- a/locations/spiders/wyndham.py\n+++ b/locations/spiders/wyndham.py\n@@ -3,6 +3,7 @@\n import re\n import scrapy\n from locations.items import GeojsonPointItem\n+from urllib.parse import urlparse, parse_qs\n \n BRAND_MAP = {\n     \"hj\": \"hojo\",\n@@ -91,19 +92,6 @@\n     \"Chile\": \"CL\",\n     \"Colombia\": \"CO\",\n }\n-HEADERS = {\n-    \"Host\": \"www.wyndhamhotels.com\",\n-    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0\",\n-    \"Accept\": \"*/*\",\n-    \"Accept-Language\": \"en-US,en;q=0.5\",\n-    \"Accept-Encoding\": \"gzip, deflate, br\",\n-    \"X-Requested-With\": \"XMLHttpRequest\",\n-    \"DNT\": \"1\",\n-    \"Connection\": \"keep-alive\",\n-    \"Referer\": \"https://www.wyndhamhotels.com/locations\",\n-    \"TE\": \"Trailers\",\n-}\n-\n \n \n def create_url(brand, city, state, unique_url, tier_id):\n@@ -126,15 +114,25 @@\n \n class WyndhamSpider(scrapy.Spider):\n     name = \"wyndham\"\n+    download_speed = 0.7\n     allowed_domains = [\"www.wyndhamhotels.com\"]\n-    headers = HEADERS\n-\n-    def start_requests(self):\n-        start_url = \"https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=&pageNumber=1&brandId=ALL&countryCode=&noPropertyData=false\"\n-        yield scrapy.Request(start_url, callback=self.parse, headers=self.headers)\n+    start_urls = (\n+        'https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=50&pageNumber=1&brandId=ALL&countryCode=US%2CCA%2CMX',\n+    )\n \n     def parse(self, response):\n         data = json.loads(response.text)\n+\n+        page_count = data.get('pageCount')\n+        parsed_url = urlparse(response.request.url)\n+        parsed_args = parse_qs(parsed_url.query)\n+        page_number = int(parsed_args['pageNumber'][0])\n+        if page_number <= page_count:\n+            next_page_number = page_number + 1\n+            yield scrapy.Request(\n+                f'https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=50&pageNumber={next_page_number}&brandId=ALL&countryCode=US%2CCA%2CMX',\n+            )\n+\n         for country in data[\"countries\"]:\n             country_code = country[\"countryCode\"]\n             for state in country[\"states\"]:\n@@ -158,7 +156,6 @@\n                                 \"country_code\": country_code,\n                                 \"brand_name\": brand_name,\n                             },\n-                            headers=HEADERS,\n                         )\n \n     def parse_property(self, response):\n", "issue": "Spider wyndham is broken\nDuring the global build at 2021-10-20-14-42-48, spider **wyndham** failed with **116 features** and **1 errors**.\n\nHere's [the log](https://data.alltheplaces.xyz/runs/2021-10-20-14-42-48/logs/wyndham.txt) and [the output](https://data.alltheplaces.xyz/runs/2021-10-20-14-42-48/output/wyndham.geojson) ([on a map](https://data.alltheplaces.xyz/map.html?show=https://data.alltheplaces.xyz/runs/2021-10-20-14-42-48/output/wyndham.geojson))\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\nimport json\nimport re\nimport scrapy\nfrom locations.items import GeojsonPointItem\n\nBRAND_MAP = {\n    \"hj\": \"hojo\",\n    \"HJ\": \"hojo\",\n    \"hojo\": \"HJ\",\n    \"lq\": \"laquinta\",\n    \"LQ\": \"laquinta\",\n    \"laquinta\": \"LQ\",\n    \"di\": \"days-inn\",\n    \"DI\": \"days-inn\",\n    \"days-inn\": \"DI\",\n    \"bh\": \"hawthorn-extended-stay\",\n    \"BH\": \"hawthorn-extended-stay\",\n    \"hawthorn-extended-stay\": \"BH\",\n    \"hr\": \"wyndham\",\n    \"HR\": \"wyndham\",\n    \"wyndham\": \"HR\",\n    \"wg\": \"wingate\",\n    \"WG\": \"wingate\",\n    \"wingate\": \"WG\",\n    \"se\": \"super-8\",\n    \"SE\": \"super-8\",\n    \"super-8\": \"SE\",\n    \"bu\": \"baymont\",\n    \"BU\": \"baymont\",\n    \"baymont\": \"BU\",\n    \"dx\": \"dolce\",\n    \"DX\": \"dolce\",\n    \"dolce\": \"DX\",\n    \"dz\": \"dazzler\",\n    \"DZ\": \"dazzler\",\n    \"dazzler\": \"DZ\",\n    \"wr\": \"wyndham-rewards\",\n    \"WR\": \"wyndham-rewards\",\n    \"wyndham-rewards\": \"WR\",\n    \"kg\": \"knights-inn\",\n    \"KG\": \"knights-inn\",\n    \"knights-inn\": \"KG\",\n    \"wt\": \"tryp\",\n    \"WT\": \"tryp\",\n    \"tryp\": \"WT\",\n    \"aa\": \"americinn\",\n    \"AA\": \"americinn\",\n    \"americinn\": \"AA\",\n    \"all\": \"wyndham-hotel-group\",\n    \"ALL\": \"wyndham-hotel-group\",\n    \"wyndham-hotel-group\": \"ALL\",\n    \"ce\": \"caesars-entertainment\",\n    \"CE\": \"caesars-entertainment\",\n    \"caesars-entertainment\": \"CE\",\n    \"mt\": \"microtel\",\n    \"MT\": \"microtel\",\n    \"microtel\": \"MT\",\n    \"gn\": \"wyndham-garden\",\n    \"GN\": \"wyndham-garden\",\n    \"wyndham-garden\": \"GN\",\n    \"gr\": \"wyndham-grand\",\n    \"GR\": \"wyndham-grand\",\n    \"wyndham-grand\": \"GR\",\n    \"es\": \"esplendor\",\n    \"ES\": \"esplendor\",\n    \"esplendor\": \"ES\",\n    \"ra\": \"ramada\",\n    \"RA\": \"ramada\",\n    \"ramada\": \"RA\",\n    \"re\": \"registry-collection\",\n    \"RE\": \"registry-collection\",\n    \"registry-collection\": \"RE\",\n    \"tl\": \"travelodge\",\n    \"TL\": \"travelodge\",\n    \"travelodge\": \"TL\",\n    \"vo\": \"wyndham-vacations\",\n    \"VO\": \"wyndham-vacations\",\n    \"wyndham-vacations\": \"VO\",\n    \"tq\": \"trademark\",\n    \"TQ\": \"trademark\",\n    \"trademark\": \"TQ\",\n}\nBRAND_TIER_MAP = {\"hr\": \"wy\", \"gr\": \"wy\", \"gn\": \"wy\", \"dz\": \"fe\", \"es\": \"fe\"}\nCOUNTRIES = {\n    \"Canada\": \"CA\",\n    \"Turkey\": \"TR\",\n    \"United States\": \"US\",\n    \"Mexico\": \"MX\",\n    \"Honduras\": \"HN\",\n    \"Chile\": \"CL\",\n    \"Colombia\": \"CO\",\n}\nHEADERS = {\n    \"Host\": \"www.wyndhamhotels.com\",\n    \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:81.0) Gecko/20100101 Firefox/81.0\",\n    \"Accept\": \"*/*\",\n    \"Accept-Language\": \"en-US,en;q=0.5\",\n    \"Accept-Encoding\": \"gzip, deflate, br\",\n    \"X-Requested-With\": \"XMLHttpRequest\",\n    \"DNT\": \"1\",\n    \"Connection\": \"keep-alive\",\n    \"Referer\": \"https://www.wyndhamhotels.com/locations\",\n    \"TE\": \"Trailers\",\n}\n\n\n\ndef create_url(brand, city, state, unique_url, tier_id):\n    # In the html, there is a script which this recreates\n    brand_name = BRAND_MAP.get(brand)\n    if not brand_name:\n        brand_name = BRAND_MAP.get(tier_id.lower())\n    url = brand_name + \"/\"\n    url += city.replace(\" \", \"-\").replace(\".\",\"\").lower()\n    state_name = (\n        f\"-{state.replace(' ','-').lower()}\"\n        if state.lower() != \"other than us/canada\"\n        else \"\"\n    )\n    url += state_name + \"/\"\n    url += unique_url.lower() + \"/\"\n    url += \"overview\"\n    return url\n\n\nclass WyndhamSpider(scrapy.Spider):\n    name = \"wyndham\"\n    allowed_domains = [\"www.wyndhamhotels.com\"]\n    headers = HEADERS\n\n    def start_requests(self):\n        start_url = \"https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=&pageNumber=1&brandId=ALL&countryCode=&noPropertyData=false\"\n        yield scrapy.Request(start_url, callback=self.parse, headers=self.headers)\n\n    def parse(self, response):\n        data = json.loads(response.text)\n        for country in data[\"countries\"]:\n            country_code = country[\"countryCode\"]\n            for state in country[\"states\"]:\n                state_name = state[\"stateName\"]\n                for city in state[\"cities\"]:\n                    city_name = city[\"cityName\"]\n                    for property_ in city[\"propertyList\"]:\n                        property_id = property_[\"propertyId\"]\n                        brand_id = property_[\"brandId\"]\n                        brand_name = property_[\"brand\"]\n                        brand_tier = property_[\"tierId\"]\n                        unique_url = property_[\"uniqueUrl\"]\n                        url = create_url(\n                            brand_id, city_name, state_name, unique_url, brand_tier\n                        )\n                        yield scrapy.Request(\n                            f\"https://{self.allowed_domains[0]}/{url}\",\n                            self.parse_property,\n                            meta={\n                                \"id\": property_id,\n                                \"country_code\": country_code,\n                                \"brand_name\": brand_name,\n                            },\n                            headers=HEADERS,\n                        )\n\n    def parse_property(self, response):\n        raw_json = re.search(\n            r'<script type=\"application\\/ld\\+json\"\\>(.+?)\\<',\n            response.text,\n            flags=re.DOTALL,\n        )\n        if not raw_json:\n            return None\n        data = json.loads(raw_json.group(1).replace(\"\\t\",\" \"))\n        properties = {\n            \"ref\": response.meta[\"id\"],\n            \"lat\": data[\"geo\"][\"latitude\"],\n            \"lon\": data[\"geo\"][\"longitude\"],\n            \"name\": data[\"name\"],\n            \"addr_full\": data[\"address\"][\"streetAddress\"],\n            \"city\": data[\"address\"][\"addressLocality\"],\n            \"state\": data[\"address\"].get(\"addressRegion\"),\n            \"postcode\": data[\"address\"].get(\"postalCode\"),\n            \"country\": response.meta[\"country_code\"],\n            \"phone\": data[\"telephone\"],\n            \"website\": response.url,\n            \"brand\": response.meta[\"brand_name\"],\n        }\n        yield GeojsonPointItem(**properties)\n", "path": "locations/spiders/wyndham.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\nimport json\nimport re\nimport scrapy\nfrom locations.items import GeojsonPointItem\nfrom urllib.parse import urlparse, parse_qs\n\nBRAND_MAP = {\n    \"hj\": \"hojo\",\n    \"HJ\": \"hojo\",\n    \"hojo\": \"HJ\",\n    \"lq\": \"laquinta\",\n    \"LQ\": \"laquinta\",\n    \"laquinta\": \"LQ\",\n    \"di\": \"days-inn\",\n    \"DI\": \"days-inn\",\n    \"days-inn\": \"DI\",\n    \"bh\": \"hawthorn-extended-stay\",\n    \"BH\": \"hawthorn-extended-stay\",\n    \"hawthorn-extended-stay\": \"BH\",\n    \"hr\": \"wyndham\",\n    \"HR\": \"wyndham\",\n    \"wyndham\": \"HR\",\n    \"wg\": \"wingate\",\n    \"WG\": \"wingate\",\n    \"wingate\": \"WG\",\n    \"se\": \"super-8\",\n    \"SE\": \"super-8\",\n    \"super-8\": \"SE\",\n    \"bu\": \"baymont\",\n    \"BU\": \"baymont\",\n    \"baymont\": \"BU\",\n    \"dx\": \"dolce\",\n    \"DX\": \"dolce\",\n    \"dolce\": \"DX\",\n    \"dz\": \"dazzler\",\n    \"DZ\": \"dazzler\",\n    \"dazzler\": \"DZ\",\n    \"wr\": \"wyndham-rewards\",\n    \"WR\": \"wyndham-rewards\",\n    \"wyndham-rewards\": \"WR\",\n    \"kg\": \"knights-inn\",\n    \"KG\": \"knights-inn\",\n    \"knights-inn\": \"KG\",\n    \"wt\": \"tryp\",\n    \"WT\": \"tryp\",\n    \"tryp\": \"WT\",\n    \"aa\": \"americinn\",\n    \"AA\": \"americinn\",\n    \"americinn\": \"AA\",\n    \"all\": \"wyndham-hotel-group\",\n    \"ALL\": \"wyndham-hotel-group\",\n    \"wyndham-hotel-group\": \"ALL\",\n    \"ce\": \"caesars-entertainment\",\n    \"CE\": \"caesars-entertainment\",\n    \"caesars-entertainment\": \"CE\",\n    \"mt\": \"microtel\",\n    \"MT\": \"microtel\",\n    \"microtel\": \"MT\",\n    \"gn\": \"wyndham-garden\",\n    \"GN\": \"wyndham-garden\",\n    \"wyndham-garden\": \"GN\",\n    \"gr\": \"wyndham-grand\",\n    \"GR\": \"wyndham-grand\",\n    \"wyndham-grand\": \"GR\",\n    \"es\": \"esplendor\",\n    \"ES\": \"esplendor\",\n    \"esplendor\": \"ES\",\n    \"ra\": \"ramada\",\n    \"RA\": \"ramada\",\n    \"ramada\": \"RA\",\n    \"re\": \"registry-collection\",\n    \"RE\": \"registry-collection\",\n    \"registry-collection\": \"RE\",\n    \"tl\": \"travelodge\",\n    \"TL\": \"travelodge\",\n    \"travelodge\": \"TL\",\n    \"vo\": \"wyndham-vacations\",\n    \"VO\": \"wyndham-vacations\",\n    \"wyndham-vacations\": \"VO\",\n    \"tq\": \"trademark\",\n    \"TQ\": \"trademark\",\n    \"trademark\": \"TQ\",\n}\nBRAND_TIER_MAP = {\"hr\": \"wy\", \"gr\": \"wy\", \"gn\": \"wy\", \"dz\": \"fe\", \"es\": \"fe\"}\nCOUNTRIES = {\n    \"Canada\": \"CA\",\n    \"Turkey\": \"TR\",\n    \"United States\": \"US\",\n    \"Mexico\": \"MX\",\n    \"Honduras\": \"HN\",\n    \"Chile\": \"CL\",\n    \"Colombia\": \"CO\",\n}\n\n\ndef create_url(brand, city, state, unique_url, tier_id):\n    # In the html, there is a script which this recreates\n    brand_name = BRAND_MAP.get(brand)\n    if not brand_name:\n        brand_name = BRAND_MAP.get(tier_id.lower())\n    url = brand_name + \"/\"\n    url += city.replace(\" \", \"-\").replace(\".\",\"\").lower()\n    state_name = (\n        f\"-{state.replace(' ','-').lower()}\"\n        if state.lower() != \"other than us/canada\"\n        else \"\"\n    )\n    url += state_name + \"/\"\n    url += unique_url.lower() + \"/\"\n    url += \"overview\"\n    return url\n\n\nclass WyndhamSpider(scrapy.Spider):\n    name = \"wyndham\"\n    download_speed = 0.7\n    allowed_domains = [\"www.wyndhamhotels.com\"]\n    start_urls = (\n        'https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=50&pageNumber=1&brandId=ALL&countryCode=US%2CCA%2CMX',\n    )\n\n    def parse(self, response):\n        data = json.loads(response.text)\n\n        page_count = data.get('pageCount')\n        parsed_url = urlparse(response.request.url)\n        parsed_args = parse_qs(parsed_url.query)\n        page_number = int(parsed_args['pageNumber'][0])\n        if page_number <= page_count:\n            next_page_number = page_number + 1\n            yield scrapy.Request(\n                f'https://www.wyndhamhotels.com/BWSServices/services/search/properties?recordsPerPage=50&pageNumber={next_page_number}&brandId=ALL&countryCode=US%2CCA%2CMX',\n            )\n\n        for country in data[\"countries\"]:\n            country_code = country[\"countryCode\"]\n            for state in country[\"states\"]:\n                state_name = state[\"stateName\"]\n                for city in state[\"cities\"]:\n                    city_name = city[\"cityName\"]\n                    for property_ in city[\"propertyList\"]:\n                        property_id = property_[\"propertyId\"]\n                        brand_id = property_[\"brandId\"]\n                        brand_name = property_[\"brand\"]\n                        brand_tier = property_[\"tierId\"]\n                        unique_url = property_[\"uniqueUrl\"]\n                        url = create_url(\n                            brand_id, city_name, state_name, unique_url, brand_tier\n                        )\n                        yield scrapy.Request(\n                            f\"https://{self.allowed_domains[0]}/{url}\",\n                            self.parse_property,\n                            meta={\n                                \"id\": property_id,\n                                \"country_code\": country_code,\n                                \"brand_name\": brand_name,\n                            },\n                        )\n\n    def parse_property(self, response):\n        raw_json = re.search(\n            r'<script type=\"application\\/ld\\+json\"\\>(.+?)\\<',\n            response.text,\n            flags=re.DOTALL,\n        )\n        if not raw_json:\n            return None\n        data = json.loads(raw_json.group(1).replace(\"\\t\",\" \"))\n        properties = {\n            \"ref\": response.meta[\"id\"],\n            \"lat\": data[\"geo\"][\"latitude\"],\n            \"lon\": data[\"geo\"][\"longitude\"],\n            \"name\": data[\"name\"],\n            \"addr_full\": data[\"address\"][\"streetAddress\"],\n            \"city\": data[\"address\"][\"addressLocality\"],\n            \"state\": data[\"address\"].get(\"addressRegion\"),\n            \"postcode\": data[\"address\"].get(\"postalCode\"),\n            \"country\": response.meta[\"country_code\"],\n            \"phone\": data[\"telephone\"],\n            \"website\": response.url,\n            \"brand\": response.meta[\"brand_name\"],\n        }\n        yield GeojsonPointItem(**properties)\n", "path": "locations/spiders/wyndham.py"}]}