22
33import logging
44import requests
5+ from urllib .parse import urljoin
56from mechanicalsoup import Browser
67from bs4 import BeautifulSoup
78from pycaching .cache import Cache , Type , Size
89from pycaching .geo import Point
10+ from pycaching .trackable import Trackable
911from pycaching .errors import Error , NotLoggedInException , LoginFailedException
1012from pycaching .util import parse_date
1113
1214
1315class Geocaching (object ):
1416
15- _baseurl = "http ://www.geocaching.com"
17+ _baseurl = "https ://www.geocaching.com"
1618 _urls = {
1719 "login_page" : "login/default.aspx" ,
1820 "search" : "play/search" ,
@@ -28,8 +30,7 @@ def _request(self, url, *, expect="soup", method="GET", login_check=True, **kwar
2830 if login_check and self ._logged_in is False :
2931 raise NotLoggedInException ("Login is needed." )
3032
31- # TODO maybe use urljoin()
32- url = url if "//" in url else "/" .join ([self ._baseurl , url ])
33+ url = url if "//" in url else urljoin (self ._baseurl , url )
3334
3435 try :
3536 res = self ._browser .request (method , url , ** kwargs )
@@ -206,3 +207,16 @@ def search_quick(self, area, *, strict=False, zoom=None):
206207 else :
207208 # can yield more caches (which are not exactly in desired area)
208209 yield cache
210+
211+ # add some shortcuts ensure backwards compatibility
212+
213+ def geocode (self , location ):
214+ return Point .from_location (self , location )
215+
216+ def load_cache (self , wp ):
217+ """Return a cache by its WP."""
218+ return Cache (self , wp )
219+
220+ def load_trackable (self , tid ):
221+ """Return a cache by its TID."""
222+ return Trackable (self , tid )
0 commit comments