Skip to main content

Geocaching.com site crawler. Provides tools for searching, fetching caches and geocoding.

Project description

Complete documentation can be found at Read the Docs.

Features

  • login to Geocaching.com

  • search caches

    • normal search (unlimited number of caches from any point)

    • quick search (all caches inside some area) - currently not working, see below

  • get cache and its details

    • normal loading (can load all details)

    • quick loading (can load just basic info but very quickly)

    • load logbook for given cache

  • get trackable details by tracking code

  • post log for a cache or a trackable

  • geocode given location

Installation

Stable version - using pip:

pip install pycaching

Dev version - manually from GIT:

git clone https://github.com/tomasbedrich/pycaching.git
cd pycaching
pip install .

Pycaching has following requirements:

Python>=3.5
requests>=2.8
beautifulsoup4>=4.9
geopy>=1.11

Pycaching tests have the following additional requirements:

betamax >=0.8, <0.9
betamax-serializers >=0.2, <0.3

Examples

Login

Simply call pycaching.login() method and it will do everything for you.

import pycaching
geocaching = pycaching.login("user", "pass")

If you won’t provide an username or password, pycaching will try to load .gc_credentials file from current directory or home folder. It will try to parse it as JSON and use the keys username and password from that file as login credentials.

# sample .gc_credentials JSON file
{ "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 calling pycaching.login(), e.g. pycaching.login("myusername2"). The first username and password tuple specified will be used as default if pycaching.login() is called without providing a username.

# sample .gc_credentials JSON file with mutiple users
[ { "username": "myusername1", "password": "mypassword1" },
  { "username": "myusername2", "password": "mypassword2" } ]
import pycaching
geocaching = pycaching.login()  # assume the .gc_credentials file is presented

In 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 the password_cmd key instead of password.

# sample .gc_credentials JSON file with password command
{ "username": "myusername", "password_cmd": "pass geocaching.com/myUsername" }

Note that the password and password_cmd keys are mutually exclusive.

Load a cache details

cache = geocaching.get_cache("GC1PAR2")
print(cache.name)  # cache.load() is automatically called
print(cache.location)  # stored in cache, printed immediately

This uses lazy loading, so the Cache object 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 while
print(cache.name)  # stored in cache, printed immediately
print(cache.location)  # NOT stored in cache, will trigger full loading

You can also load a logbook for cache:

for log in cache.load_logbook(limit=200):
    print(log.visited, log.type, log.author, log.text)

Or its trackables:

for trackable in cache.load_trackables(limit=5):
    print(trackable.name)

Post a log to cache

geocaching.post_log("GC1PAR2", "Found cache in the rain. Nice place, TFTC!")

It is also possible to call post_log on Cache object, but you would have to create Log object manually and pass it to this method.

Search for all traditional caches around

from pycaching import Point
from pycaching.cache import Type

point = Point(56.25263, 15.26738)

for cache in geocaching.search(point, limit=50):
    if cache.type == Type.traditional:
        print(cache.name)

Notice the limit in the search function. It is because geocaching.search() returns a generator object, which would fetch the caches forever in case of a simple loop.

Geocode adress and search around

point = geocaching.geocode("Prague")

for cache in geocaching.search(point, limit=10):
    print(cache.name)

Find caches with their approximate locations in some area

from pycaching import Point, Rectangle

rect = Rectangle(Point(60.15, 24.95), Point(60.17, 25.00))

for cache in geocaching.search_quick(rect, strict=True):
    print(cache.name, cache.location.precision)

Load trackable details

trackable = geocaching.get_trackable("TB3ZGT2")
print(trackable.name, trackable.goal, trackable.description, trackable.location)

Post a log for trackable

from pycaching.log import Log, Type as LogType
import datetime

log = 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 type

from pycaching.log import Type as LogType

for find in geocaching.my_finds(limit=5):
    print(find.name)

for dnf in geocaching.my_dnfs(limit=2):
    print(dnf.name)

for note in geocaching.my_logs(LogType.note, limit=6):
    print(note.name)

Testing

Pycaching uses Betamax for testing, which speeds it up by recording network requests so that they can be mocked.

If you haven’t written or modified any tests, tests can be run like so:

python3 setup.py test

If you have written or modified tests, you must provide a username and password for testing. Don’t worry, these will not leave your computer. Betamax will insert a placeholder when it records any new cassettes. To run new tests, first set up the following environment variables:

PYCACHING_TEST_USERNAME="yourusername" PYCACHING_TEST_PASSWORD="yourpassword" python3 setup.py test

Substitute your username for yourusername and your password for yourpassword. After you have exported the environment variables once, you do not need to export them again, and can run tests with just python3 setup.py test.

To re-record a specific cassette in case of site changes, delete the corresponding JSON file and provide username and password as explained above. The missing cassette will be recorded for future usages.

Appendix

Inspiration

Original version was inspired by these packages:

Although the new version was massively rewritten, I’d like to thank to their authors.

Authors

Authors of this project are all contributors. Maintainer is Tomáš Bedřich.

Build Status Coverage Status PyPI monthly downloads

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pycaching-4.2.1.tar.gz (50.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

pycaching-4.2.1-py3.6.egg (37.7 kB view details)

Uploaded Egg

pycaching-4.2.1-py3-none-any.whl (40.7 kB view details)

Uploaded Python 3

File details

Details for the file pycaching-4.2.1.tar.gz.

File metadata

  • Download URL: pycaching-4.2.1.tar.gz
  • Upload date:
  • Size: 50.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.7

File hashes

Hashes for pycaching-4.2.1.tar.gz
Algorithm Hash digest
SHA256 d5f1c769daf6e2efe9e898b5e48558cbe9384a31d620a69952ab3f5df1c4bca8
MD5 99f9fa3d24da277db96c9e22bdac9c62
BLAKE2b-256 6bec4947eee642bf50e095a411a462139071e7a0dda6dfd66f996a0a4dedfa48

See more details on using hashes here.

File details

Details for the file pycaching-4.2.1-py3.6.egg.

File metadata

  • Download URL: pycaching-4.2.1-py3.6.egg
  • Upload date:
  • Size: 37.7 kB
  • Tags: Egg
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.7

File hashes

Hashes for pycaching-4.2.1-py3.6.egg
Algorithm Hash digest
SHA256 bd9f60473bd57998e5d7b67e89d41a75e0cb0cb1854d66d148ddc47799613bc5
MD5 01661eafa8ef3198701bda956dca783b
BLAKE2b-256 5281d9186f8b9fc2f236743f8459b76f444cd72e013939a0137fe462003e071f

See more details on using hashes here.

File details

Details for the file pycaching-4.2.1-py3-none-any.whl.

File metadata

  • Download URL: pycaching-4.2.1-py3-none-any.whl
  • Upload date:
  • Size: 40.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.6.7

File hashes

Hashes for pycaching-4.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 578a01f3a9da52374e1d7c212be3a10ac805d168d2b755df9677c083d931c0b9
MD5 4f4236d4aebe73838137fe9875e0c473
BLAKE2b-256 82650b9f98e4bc97bee6acfd31ec9a223d7d814832b5c469a0d9653a15105d1f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page