Repository: alltheplaces/alltheplaces

Issue:
Gold's Gym
https://www.goldsgym.com/gym_market-sitemap.xml
Gold's Gym
https://www.goldsgym.com/gym_market-sitemap.xml


Discussion:
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.
Will be spending a lot of time hammering out some scripts tonight, reassigning myself for tonight and will unassign myself if I don't complete it by tomorrow morning. 
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.
Will be spending a lot of time hammering out some scripts tonight, reassigning myself for tonight and will unassign myself if I don't complete it by tomorrow morning. 

Resolving patch:
diff --git a/locations/spiders/goldsgym.py b/locations/spiders/goldsgym.py
new file mode 100644
--- /dev/null
+++ b/locations/spiders/goldsgym.py
@@ -0,0 +1,68 @@
+import json
+import re
+from urllib.parse import urlparse
+import scrapy
+from scrapy.selector import Selector
+
+from locations.items import GeojsonPointItem
+from locations.hours import OpeningHours
+
+
+class GoldsGymSpider(scrapy.Spider):
+    name = "goldsgym"
+    allowed_domains = ["goldsgym.com"]
+
+    start_urls = [
+        "https://www.goldsgym.com/gym_index-sitemap.xml",
+    ]
+
+    def parse_hours(self, hours):
+        opening_hours = OpeningHours()
+        for group in hours:
+            days, open_time, close_time = re.search(r'([a-zA-Z,]+)\s([\d:]+)-([\d:]+)', group).groups()
+            days = days.split(',')
+            for day in days:
+                opening_hours.add_range(day=day, open_time=open_time, close_time=close_time, time_format='%H:%M')
+
+        return opening_hours.as_opening_hours()
+
+    def parse_hotel(self, response):
+        if 'locate-a-gym' in response.url or '/markets/' in response.url:
+            return  # closed gym, redirects
+
+        data = response.xpath('//script[@type="application/ld+json"]/text()').extract_first()
+        if data:
+            data = json.loads(data)
+        else:
+            return  # closed gym
+
+        properties = {
+            'ref': "_".join([x for x in response.url.split('/')[-2:] if x]),
+            'name': data["name"],
+            'addr_full': data["address"]["streetAddress"].strip(),
+            'city': data["address"]["addressLocality"].strip(),
+            'state': data["address"]["addressRegion"],
+            'postcode': data["address"]["postalCode"],
+            'country': data["address"]["addressCountry"],
+            'phone': data.get("telephone", None),
+            'lat': float(data["geo"]["latitude"]),
+            'lon': float(data["geo"]["longitude"]),
+            'website': response.url,
+        }
+
+        hours = self.parse_hours(data["openingHours"])
+        if hours:
+            properties["opening_hours"] = hours
+
+        yield GeojsonPointItem(**properties)
+
+    def parse(self, response):
+        xml = Selector(response)
+        xml.remove_namespaces()
+
+        urls = xml.xpath('//loc/text()').extract()
+        for url in urls:
+            path = "/".join(urlparse(url).path.split('/')[:-1])
+            yield scrapy.Request(response.urljoin(path), callback=self.parse_hotel)
+
+


Test patch: