@@ -488,6 +488,11 @@ def load(self):
488
488
Use full cache details page. Therefore all possible properties are filled in, but the
489
489
loading is a bit slow.
490
490
491
+ If you want to load basic details about a PM only cache, the :class:`.PMOnlyException` is
492
+ still thrown, but avaliable details are filled in. If you know, that the cache you are
493
+ loading is PM only, please consider using :meth:`load_quick` as it will load the same
494
+ details, but quicker.
495
+
491
496
.. note::
492
497
This method is called automatically when you access a property which isn't yet filled in
493
498
(so-called "lazy loading"). You don't have to call it explicitly.
@@ -509,65 +514,92 @@ def load(self):
509
514
raise errors .LoadError ("Error in loading cache" ) from e
510
515
511
516
# check for PM only caches if using free account
512
- if root .find ("p" , "PMOWarning" ) is not None :
513
- raise errors .PMOnlyException ("Premium Members only." )
514
-
515
- cache_details = root .find (id = "cacheDetails" )
516
- attributes_widget , inventory_widget , * \
517
- bookmarks_widget = root .find_all ("div" , "CacheDetailNavigationWidget" )
518
-
519
- # parse raw data
520
- wp = root .title .string .split (" " )[0 ]
521
- name = cache_details .find ("h2" )
522
- type = cache_details .find ("img" ).get ("src" ).split (
523
- "/" )[- 1 ].rsplit ("." , 1 )[0 ] # filename w/o extension
524
- author = cache_details ("a" )[1 ]
525
- hidden = cache_details .find ("div" , "minorCacheDetails" ).find_all ("div" )[1 ]
526
- location = root .find (id = "uxLatLon" )
527
- state = root .find ("ul" , "OldWarning" )
528
- found = root .find ("div" , "FoundStatus" )
529
- D_T = root .find ("div" , "CacheStarLabels" ).find_all ("img" )
530
- size = root .find ("div" , "CacheSize" ).find ("img" )
531
- attributes_raw = attributes_widget .find_all ("img" )
532
- user_content = root .find_all ("div" , "UserSuppliedContent" )
533
- hint = root .find (id = "div_hint" )
534
- favorites = root .find ("span" , "favorite-value" )
517
+ self .pm_only = root .find ("p" , "PMOWarning" ) is not None
535
518
536
- # load logbook_token
537
- js_content = "\n " .join (map (lambda i : i .text , root .find_all ("script" )))
538
- logbook_token = re .findall ("userToken\\ s*=\\ s*'([^']+)'" , js_content )[0 ]
519
+ cache_details = root .find (id = "ctl00_divContentMain" ) if self .pm_only else root .find (id = "cacheDetails" )
520
+
521
+ # details also avaliable for basic members for PM only caches -----------------------------
522
+
523
+ if self .pm_only :
524
+ # parse from title in format: "cache name (WAYPOINT)"
525
+ self .wp = cache_details .find ("h2" ).text .split ("(" )[- 1 ].strip (")" )
526
+
527
+ name = cache_details .find ("h2" ).text
528
+ self .name = name .rsplit ("(" , 1 )[0 ] if self .pm_only else name # everything before last bracket
529
+
530
+ author = root .find (id = "ctl00_ContentBody_uxCacheType" ).text
531
+ self .author = author [len ("A cache by " ):]
532
+
533
+ size = root .find ("p" , "PMCacheInfoSpacing" )
534
+
535
+ # skip first, which is size <img>
536
+ D_and_T_img = root .find ("p" , "PMCacheInfoSpacing" ).find_all ("img" )[1 :]
539
537
540
- # if there are some trackables
541
- if len (inventory_widget .find_all ("a" )) >= 3 :
542
- trackable_page_url = inventory_widget .find (
543
- id = "ctl00_ContentBody_uxTravelBugList_uxViewAllTrackableItems" ).get ("href" )[3 :] # has "../" on start
544
538
else :
545
- trackable_page_url = None
539
+ # parse from <title> - get first word
540
+ self .wp = root .title .string .split (" " )[0 ]
546
541
547
- log_page_url = root .find (id = "ctl00_ContentBody_GeoNav_logButton" )["href" ]
548
- # prettify data
549
- self .wp = wp
550
- self .name = name .text
542
+ self .name = cache_details .find ("h2" ).text
543
+
544
+ self .author = cache_details ("a" )[1 ].text
545
+
546
+ size = root .find ("div" , "CacheSize" )
547
+
548
+ D_and_T_img = root .find ("div" , "CacheStarLabels" ).find_all ("img" )
549
+
550
+ size = size .find ("img" ).get ("src" ) # size img src
551
+ size = size .split ("/" )[- 1 ].rsplit ("." , 1 )[0 ] # filename w/o extension
552
+ self .size = Size .from_filename (size )
553
+
554
+ self .difficulty , self .terrain = [float (img .get ("alt" ).split ()[0 ]) for img in D_and_T_img ]
555
+
556
+ type = cache_details .find ("img" ).get ("src" ) # type img src
557
+ type = type .split ("/" )[- 1 ].rsplit ("." , 1 )[0 ] # filename w/o extension
551
558
self .type = Type .from_filename (type )
552
- self .author = author .text
553
- self .hidden = parse_date (hidden .text .split (":" )[- 1 ])
554
- self .location = Point .from_string (location .text )
555
- self .state = state is None
559
+
560
+ if self .pm_only :
561
+ raise errors .PMOnlyException ()
562
+
563
+ # details not avaliable for basic members for PM only caches ------------------------------
564
+
565
+ attributes_widget , inventory_widget , * _ = root .find_all ("div" , "CacheDetailNavigationWidget" )
566
+
567
+ hidden = cache_details .find ("div" , "minorCacheDetails" ).find_all ("div" )[1 ].text
568
+ self .hidden = parse_date (hidden .split (":" )[- 1 ])
569
+
570
+ self .location = Point .from_string (root .find (id = "uxLatLon" ).text )
571
+
572
+ self .state = root .find ("ul" , "OldWarning" ) is None
573
+
574
+ found = root .find ("div" , "FoundStatus" )
556
575
self .found = found and ("Found It!" or "Attended" in found .text ) or False
557
- self .difficulty , self .terrain = [float (_ .get ("alt" ).split ()[0 ]) for _ in D_T ]
558
- self .size = Size .from_filename (size .get ("src" ).split (
559
- "/" )[- 1 ].rsplit ("." , 1 )[0 ]) # filename w/o extension
576
+
577
+ attributes_raw = attributes_widget .find_all ("img" )
560
578
attributes_raw = [_ .get ("src" ).split ("/" )[- 1 ].rsplit ("-" , 1 ) for _ in attributes_raw ]
561
- self .attributes = {attribute_name : appendix .startswith ("yes" )
562
- for attribute_name , appendix in attributes_raw if not appendix .startswith ("blank" )}
579
+
580
+ self .attributes = {attribute_name : appendix .startswith ("yes" ) for attribute_name , appendix
581
+ in attributes_raw if not appendix .startswith ("blank" )}
582
+
583
+ user_content = root .find_all ("div" , "UserSuppliedContent" )
563
584
self .summary = user_content [0 ].text
564
585
self .description = str (user_content [1 ])
565
- self .hint = rot13 (hint .text .strip ())
586
+
587
+ self .hint = rot13 (root .find (id = "div_hint" ).text .strip ())
588
+
589
+ favorites = root .find ("span" , "favorite-value" )
566
590
self .favorites = 0 if favorites is None else int (favorites .text )
567
591
568
- self ._logbook_token = logbook_token
569
- self ._trackable_page_url = trackable_page_url
570
- self ._log_page_url = log_page_url
592
+ self ._log_page_url = root .find (id = "ctl00_ContentBody_GeoNav_logButton" )["href" ]
593
+
594
+ js_content = "\n " .join (map (lambda i : i .text , root .find_all ("script" )))
595
+ self ._logbook_token = re .findall ("userToken\\ s*=\\ s*'([^']+)'" , js_content )[0 ]
596
+
597
+ # if there are some trackables
598
+ if len (inventory_widget .find_all ("a" )) >= 3 :
599
+ trackable_page_url = inventory_widget .find (id = "ctl00_ContentBody_uxTravelBugList_uxViewAllTrackableItems" )
600
+ self ._trackable_page_url = trackable_page_url .get ("href" )[3 :] # has "../" on start
601
+ else :
602
+ self ._trackable_page_url = None
571
603
572
604
logging .debug ("Cache loaded: {}" .format (self ))
573
605
0 commit comments