Skip to content

Commit c2dcea0

Browse files
FriedrichFroebeltomasbedrich
authored andcommitted
Fix loading premium cache details for basic members (#131)
1 parent 88a4268 commit c2dcea0

File tree

2 files changed

+43
-34
lines changed

2 files changed

+43
-34
lines changed

pycaching/cache.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -630,25 +630,21 @@ def load(self):
630630
else:
631631
raise errors.LoadError("Cache lacks info for loading")
632632
except errors.Error as e:
633-
# probably 404 during cache loading - cache not exists
633+
# probably 404 during cache loading - cache does not exist
634634
raise errors.LoadError("Error in loading cache") from e
635635

636636
# check for PM only caches if using free account
637-
self.pm_only = root.find("section", "pmo-banner") is not None
637+
self.pm_only = root.find("section", "premium-upgrade-widget") is not None
638638

639639
cache_details = root.find(id="ctl00_divContentMain") if self.pm_only else root.find(id="cacheDetails")
640640

641-
# details also avaliable for basic members for PM only caches -----------------------------
641+
# details also available for basic members for PM only caches -----------------------------
642642

643643
if self.pm_only:
644644
self.wp = cache_details.find("li", "li__gccode").text.strip()
645645

646646
self.name = cache_details.find("h1").text.strip()
647647

648-
type = cache_details.find("img").get("src") # "/play/Content/images/cache-types/3.png"
649-
type = type.split("/")[-1].rsplit(".", 1)[0] # "3"
650-
self.type = Type.from_filename(type)
651-
652648
author = cache_details.find(id="ctl00_ContentBody_uxCacheBy").text
653649
self.author = author[len("A cache by "):]
654650

@@ -670,10 +666,6 @@ def load(self):
670666
raise errors.LoadError()
671667
self.name = cache_details.find("h2").text
672668

673-
type = cache_details.select_one("svg.cache-icon use").get("xlink:href") # "cache-types.svg#icon-3-disabled"
674-
type = type.split("#")[-1].replace("_", "-").split("-")[1] # "3"
675-
self.type = Type.from_filename(type)
676-
677669
self.author = cache_details("a")[1].text
678670

679671
D_and_T_img = root.find("div", "CacheStarLabels").find_all("img")
@@ -684,6 +676,11 @@ def load(self):
684676
size = size.split("/")[-1].rsplit(".", 1)[0] # filename w/o extension
685677
self.size = Size.from_filename(size)
686678

679+
# use shared functionality as both cases use the same method
680+
type = cache_details.select_one("svg.cache-icon use").get("xlink:href") # "cache-types.svg#icon-3-disabled"
681+
type = type.split("#")[-1].replace("_", "-").split("-")[1] # "3"
682+
self.type = Type.from_filename(type)
683+
687684
if self.pm_only:
688685
raise errors.PMOnlyException()
689686

0 commit comments

Comments
 (0)