Skip to content

Commit 4cf6e87

Browse files
committed
Fixed load_print parsing GUID, attributes, favorites
1 parent c2a40c0 commit 4cf6e87

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

pycaching/cache.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import re
66
import enum
77
import os
8-
import urllib.parse as urlparse
8+
from urllib.parse import urlparse, parse_qs
99
from pycaching import errors
1010
from pycaching.geo import Point
1111
from pycaching.trackable import Trackable
@@ -616,9 +616,9 @@ def load(self):
616616

617617
# details not avaliable for basic members for PM only caches ------------------------------
618618

619-
parsed_url = urlparse(root.find(id="ctl00_ogUrl").get("content"))
620-
query_string = urlparse.parse_qs(parsed_url)
621-
self.guid = query_string['guid']
619+
parsed_url = urlparse(root.find("link", rel="canonical").get("href"))
620+
query_string = parse_qs(parsed_url.query)
621+
self.guid = query_string['guid'][0]
622622

623623
pm_only_warning = root.find("p", "Warning NoBottomSpacing")
624624
self.pm_only = pm_only_warning and ("Premium Member Only" in pm_only_warning.text) or False
@@ -754,7 +754,8 @@ def load_by_guid(self):
754754
hidden_p = content.find("p", text=re.compile("Placed Date:"))
755755
self.hidden = hidden_p.text.replace("Placed Date:", "").strip()
756756

757-
attr_img = content.find_all("img", src=re.compile("\/attributes\/"))
757+
attributes_widget = content.find("div", "sortables")
758+
attr_img = attributes_widget.find_all("img", src=re.compile("\/attributes\/"))
758759
attributes_raw = [
759760
os.path.basename(_.get("src")).rsplit("-", 1) for _ in attr_img
760761
]
@@ -771,8 +772,8 @@ def load_by_guid(self):
771772

772773
self.hint = content.find(id="uxEncryptedHint").text
773774

774-
self.favorites = content.find(
775-
"strong", text=re.compile("Favorites:")).parent.text.split()[-1]
775+
favorites = content.find("strong", text=re.compile("Favorites:"))
776+
self.favorites = 0 if favorites is None else int(favorites.parent.text.split()[-1])
776777

777778
self.waypoints = Waypoint.from_html(content, "Waypoints")
778779

0 commit comments

Comments
 (0)