Skip to content

Commit 43ffdab

Browse files
authored
Added KML downloading for trackables
Merge pull request #70 from FriedrichFroebel/issue-62 (#62)
2 parents 4d07ffb + 1f64e7e commit 43ffdab

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

pycaching/trackable.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, geocaching, tid, *, name=None, location=None, owner=None,
3030
if url is not None:
3131
self.url = url
3232
self._log_page_url = None
33+
self._kml_url = None
3334

3435
def __str__(self):
3536
"""Return trackable ID."""
@@ -152,6 +153,15 @@ def type(self):
152153
def type(self, type):
153154
self._type = type.strip()
154155

156+
def get_KML(self):
157+
"""The kml route of the trackable.
158+
159+
:type: :class:`str`
160+
"""
161+
if not self._kml_url:
162+
self.load() # fills self._kml_url
163+
return self.geocaching._request(self._kml_url, expect="raw").text
164+
155165
def load(self):
156166
"""Load all possible details about the trackable.
157167
@@ -179,6 +189,7 @@ def load(self):
179189
self.owner = root.find(id="ctl00_ContentBody_BugDetails_BugOwner").text
180190
self.goal = root.find(id="TrackableGoal").text
181191
self.description = root.find(id="TrackableDetails").text
192+
self._kml_url = root.find(id="ctl00_ContentBody_lnkGoogleKML").get("href")
182193

183194
# another Groundspeak trick... inconsistent relative / absolute URL on one page
184195
self._log_page_url = "/track/" + root.find(id="ctl00_ContentBody_LogLink")["href"]

test/test_trackable.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,11 @@ def test_post_log(self, mock_request, mock_load_log_page):
124124
"ctl00$ContentBody$LogBookPanel1$uxLogInfo": test_log_text,
125125
}
126126
mock_request.assert_called_with(self.t._log_page_url, method="POST", data=expected_post_data)
127+
128+
def test_get_KML(self):
129+
kml = self.t.get_KML()
130+
self.assertTrue("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" in kml)
131+
self.assertTrue("<kml xmlns=\"http://earth.google.com/kml/2.2\">" in kml)
132+
self.assertTrue("#tbTravelStyle" in kml)
133+
self.assertTrue("<visibility>1</visibility>" in kml)
134+
self.assertTrue("</Placemark></Document></kml>" in kml)

0 commit comments

Comments
 (0)