Skip to content

Commit b4a04e2

Browse files
S0S-90tomasbedrich
authored andcommitted
implement requested changes
1 parent 9fec66a commit b4a04e2

File tree

2 files changed

+6
-28
lines changed

2 files changed

+6
-28
lines changed

pycaching/geocaching.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -383,26 +383,17 @@ def _cache_from_guid(self, guid):
383383
return Cache._from_print_page(self, guid, print_page)
384384

385385
def _try_getting_cache_from_guid(self, guid):
386-
"""tries to read a geocache from GUID page
387-
if this is not possible (because it's a premium only cache) it reads the cache from the GC code"""
386+
"""Try to get a cache from guid page if possible, otherwise from gccode.
387+
388+
:param str guid: guid of the cache that should be read in
389+
"""
388390
try:
389391
return self.get_cache(guid=guid)
390392
except PMOnlyException:
391-
url = "https://www.geocaching.com/seek/cache_details.aspx?guid={}".format(guid)
392-
wp = self._get_gccode_from_guidpage(url)
393+
url = self._request(Cache._urls["cache_details"], params={"guid": guid}, expect="raw").url
394+
wp = url.split("/")[4].split("_")[0] # get gccode from redirected url
393395
return self.get_cache(wp)
394396

395-
@staticmethod
396-
def _get_gccode_from_guidpage(url):
397-
data = requests.get(url).text
398-
soup = bs4.BeautifulSoup(data, features="html.parser")
399-
gc_element = soup.find("li", class_="li__gccode")
400-
if gc_element is not None: # PMonly caches, this it what this function is for
401-
gccode = gc_element.text.strip()
402-
else:
403-
gccode = soup.find("span", class_="CoordInfoCode").text.strip()
404-
return gccode
405-
406397
def my_logs(self, log_type=None, limit=float('inf')):
407398
"""Get an iterable of the logged-in user's logs.
408399

test/test_geocaching.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,19 +96,6 @@ def test_search_quick_match_load(self):
9696
except PMOnlyException:
9797
pass
9898

99-
def test__get_gccode_from_guidpage(self):
100-
# for a "normal" cache (not really relevant for program)
101-
url_normal = "https://www.geocaching.com/seek/cache_details.aspx?guid={}".format(
102-
"15ad3a3d-92c1-4f7c-b273-60937bcc2072")
103-
wp_normal = self.gc._get_gccode_from_guidpage(url_normal)
104-
self.assertEqual(wp_normal, "GC4808G")
105-
106-
# for PMonly cache
107-
url = "https://www.geocaching.com/seek/cache_details.aspx?guid={}".format(
108-
"328927c1-aa8c-4e0d-bf59-31f1ce44d990")
109-
wp = self.gc._get_gccode_from_guidpage(url)
110-
self.assertEqual(wp, "GC74HEV")
111-
11299
def test__try_getting_cache_from_guid(self):
113100
# get "normal" cache from guidpage
114101
with self.recorder.use_cassette('geocaching_shortcut_getcache__by_guid'): # is a replacement for login

0 commit comments

Comments
 (0)