Skip to main content

BC Ferries Python Library

Project description

This is the Python client library for interacting with information published on the BC Ferries mobile site. It is essentially a wrapper around a BeautifulSoup-powered scraper. Better documentation and tests are still in the works; feel free to contribute!

Installation

pip install bcferries

Usage

from bcferries import BCFerries

bc = BCFerries()
terminals = bc.terminals()
# {u'Horseshoe Bay': BCFerriesTerminal (Horseshoe Bay), u'Tsawwassen': BCFerriesTerminal (Tsawwassen)}
t = terminals['Tsawwassen']
# BCFerriesTerminal (Tsawwassen)

routes = t.routes()
# {u'Tsawwassen to Duke Point': BCFerriesRoute (Tsawwassen to Duke Point)}
r = routes['Tsawwassen to Duke Point']
# BCFerriesRoute (Tsawwassen to Duke Point)

crossing = r.crossings()['10:45pm']
# BCFerriesCrossing (Tsawwassen to Duke Point at 5:45pm)
crossing.capacity
# BCFerriesCapacity (18% Full)

All returned dictionaries have fuzzy string matching on they keys.

routes['Tsawwassen to Duke Point'] == routes['Tsaw to DP']
# True

There is also fuzzy time matching on keys that represent a nearby time.

r = routes['HBay to DBay']
schedule = r.schedule()
schedule['6:12 PM']
# BCFerriesScheduledCrossing (Queen of Cowichan at 6:30 PM)

bcferries caches the last 128 API calls by default. You can change this to any integer you want, or set it to zero to disable caching.

import bcferries.api

bcferries.api.BCFerriesAPI.cache_last = 16

You can also pass any function the ignore_cache keyword argument to bypass the cache, or call the flush_cache method on BCFerries to clear the entire cache.

terminals = bc.terminals() # initial call takes multiple seconds
terminals = bc.terminals() # repeated call returns almost instantly
terminals = bc.terminals(ignore_cache=True) # takes multiple seconds to return

bc.flush_cache() # wipes the cache

You can export any subset of information with a call to to_dict on any object. You can also use to_fuzzy_dict and to_json as needed. To export all available information, call any of these methods on a BCFerries instance, and be prepared to wait a while.

crossing.capacity
# BCFerriesCapacity (18% Full)
crossing.capacity.to_dict()
# {'passenger_filled': 32, 'mixed_filled': 4, 'name': '18% Full', 'filled': 18}

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

bcferries-0.0.6.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

bcferries-0.0.6.macosx-10.9-x86_64.tar.gz (11.4 kB view details)

Uploaded Source

File details

Details for the file bcferries-0.0.6.tar.gz.

File metadata

  • Download URL: bcferries-0.0.6.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for bcferries-0.0.6.tar.gz
Algorithm Hash digest
SHA256 7d5ac88ef9ce59c2998dee46075d41d623e7bdaac2abcb5122460db944e89d01
MD5 12f6ba20b34a780a9b13efe8f61d0550
BLAKE2b-256 6ea47461120dc807173f97754ccb065dd5a798e3eeae3c6a1e76b440242296ca

See more details on using hashes here.

File details

Details for the file bcferries-0.0.6.macosx-10.9-x86_64.tar.gz.

File metadata

File hashes

Hashes for bcferries-0.0.6.macosx-10.9-x86_64.tar.gz
Algorithm Hash digest
SHA256 ca4e86eb3868837c0d6278c5a5ce268b6c22e6945a0a8ac9c647ae2fe52db1e4
MD5 af8e781ae8d8b7ee9e05eb075b0dd752
BLAKE2b-256 44720d47e23592013212dfc55a53ef5c8770c5649b3a9f70afcdb3d516f8214e

See more details on using hashes here.

Supported by

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