Package: pycaching
Complete documentation can be found atRead the Docs.Featuresloginto Geocaching.comsearchcachesnormal search (unlimited number of caches from any point)quick search (all caches inside some area) - currently not working, see belowget cacheand its detailsnormal loading (can load all details)quick loading (can load just basic info but very quickly)load logbook for given cacheget trackabledetails by tracking codepost logfor a cache or a trackablegeocodegiven locationInstallationStable version - using pip:pipinstallpycachingDev version - manually from GIT:gitclonehttps://github.com/tomasbedrich/pycaching.gitcdpycachingpipinstall.Pycaching has following requirements:Python>=3.5
requests>=2.8
beautifulsoup4>=4.9
geopy>=1.11Pycaching tests have the following additional requirements:betamax >=0.8, <0.9
betamax-serializers >=0.2, <0.3ExamplesLoginSimply callpycaching.login()method and it will do everything for you.importpycachinggeocaching=pycaching.login("user","pass")If you won’t provide an username or password, pycaching will try to load.gc_credentialsfile
from current directory or home folder. It will try to parse it as JSON and use the keysusernameandpasswordfrom that file as login credentials.{"username":"myusername","password":"mypassword"}You can also provide multiple username and password tuples in a file as login credentials.
The tuple to be used can be chosen by providing its username when callingpycaching.login(),
e.g.pycaching.login("myusername2"). The first username and password tuple specified will be
used as default ifpycaching.login()is called without providing a username.[{"username":"myusername1","password":"mypassword1"},{"username":"myusername2","password":"mypassword2"}]importpycachinggeocaching=pycaching.login()# assume the .gc_credentials file is presentedIn case you have a password manager in place featuring a command line interface
(e.g.GNU pass) you may specify a password retrieval command
using thepassword_cmdkey instead ofpassword.{"username":"myusername","password_cmd":"pass geocaching.com/myUsername"}Note that thepasswordandpassword_cmdkeys are mutually exclusive.Load a cache detailscache=geocaching.get_cache("GC1PAR2")print(cache.name)# cache.load() is automatically calledprint(cache.location)# stored in cache, printed immediatelyThis uses lazy loading, so theCacheobject is created immediately and the page is loaded when needed (accessing the name).You can use a different method of loading cache details. It will be much faster, but it will load less
details:cache=geocaching.get_cache("GC1PAR2")cache.load_quick()# takes a small whileprint(cache.name)# stored in cache, printed immediatelyprint(cache.location)# NOT stored in cache, will trigger full loadingYou can also load a logbook for cache:forlogincache.load_logbook(limit=200):print(log.visited,log.type,log.author,log.text)Or its trackables:fortrackableincache.load_trackables(limit=5):print(trackable.name)Post a log to cachegeocaching.post_log("GC1PAR2","Found cache in the rain. Nice place, TFTC!")It is also possible to callpost_logonCacheobject, but you would have to createLogobject manually and pass it to
this method.Search for all traditional caches aroundfrompycachingimportPointfrompycaching.cacheimportTypepoint=Point(56.25263,15.26738)forcacheingeocaching.search(point,limit=50):ifcache.type==Type.traditional:print(cache.name)Notice thelimitin the search function. It is becausegeocaching.search()returns a generator object, which would fetch the caches forever in case of a simple loop.Geocode address and search aroundpoint=geocaching.geocode("Prague")forcacheingeocaching.search(point,limit=10):print(cache.name)Find caches in some areafrompycachingimportPoint,Rectanglerect=Rectangle(Point(60.15,24.95),Point(60.17,25.00))forcacheingeocaching.search_rect(rect):print(cache.name)If you want to search in a larger area, you could use thelimitparameter as described above.Load trackable detailstrackable=geocaching.get_trackable("TB3ZGT2")print(trackable.name,trackable.goal,trackable.description,trackable.location)Post a log for trackablefrompycaching.logimportLog,TypeasLogTypeimportdatetimelog=Log(type=LogType.discovered_it,text="Nice TB!",visited=datetime.date.today())tracking_code="ABCDEF"trackable.post_log(log,tracking_code)Get geocaches by log typefrompycaching.logimportTypeasLogTypeforfindingeocaching.my_finds(limit=5):print(find.name)fordnfingeocaching.my_dnfs(limit=2):print(dnf.name)fornoteingeocaching.my_logs(LogType.note,limit=6):print(note.name)AppendixLegal noticeBe sure to readGeocaching.com’s terms of use.
By using this piece of software you break them and your Geocaching account may be suspended oreven
deleted. To prevent this, I recommend you to load the data you really need, nothing more. This
software is provided “as is” and I am not responsible for any damage possibly caused by it.InspirationOriginal version was inspired by these packages:Geocache Grabber(by Fuad Tabba)geocaching-py(by Lev Shamardin)Although the new version was massively rewritten, I’d like to thank to their authors.AuthorsAuthors of this project areall contributors. Maintainer isTomáš Bedřich.