Skip to main content

Python: FireServiceRota / BrandweerRooster

Python 3 API wrapper for FireServiceRota and BrandweerRooster

About

This package allows you to get notified about emergency incidents from FireServiceRota.co.uk and BrandweerRooster.nl. Those are services used by firefighters.

See https://fireservicerota.co.uk and https://brandweerrooster.nl for more details.

NOTE: You need a subscription and login account to be able to use it.

Installation

pip3 install pyfireservicerota

Usage

from pyfireservicerota import FireServiceRotaOAuth, FireServiceRotaOauthError, FireServiceRotaIncidentsListener
import logging
import sys
import json
import time
import threading

_LOGGER = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG)

oauth = FireServiceRotaOAuth(
        "https://www.brandweerrooster.nl/oauth/token",
        "",
        [USERNAME],
        [PASSWORD],
    )

try:
    token_info = oauth.get_access_token()
except FireServiceRotaOauthError:
    token_info = None

if not token_info:
    _LOGGER.error("Failed to get access token")

wsurl = f"wss://www.brandweerrooster.nl/cable?access_token={token_info['access_token']}"


class FireService():

    def __init__(self):

        self._data = None
        self.listener = None
        self.thread = threading.Thread(target=self.incidents_listener)
        self.thread.daemon = True
        self.thread.start()

    def on_incident(self, data):
        _LOGGER.debug("INCIDENT: %s", data)
        self._data = data

    @property
    def data(self):
        """Return the current data stored in the provider."""
        return self._data

    def incidents_listener(self):
        """Spawn a new Listener and links it to self.on_incident."""

        _LOGGER.debug("Starting incidents listener")
        self.listener = FireServiceRotaIncidentsListener(url=wsurl, on_incident=self.on_incident)

        while True:
            try:
                self.listener.run_forever()
            except:
                pass


ws = FireService()

while True:
    time.sleep(1)

Don't store user credentuals, just the token_info and use below code to refresh it, it will only fetch new token when it has expired. If you want to force a token refresh add True as param to oauth.refresh_acess_token()

oauth = FireServiceRotaOAuth(
        "https://www.brandweerrooster.nl/oauth/token",
        "",
        "",
        "",
    )

try:
    token_info = oauth.refresh_access_token(current_token_info)
except FireServiceRotaOauthError:
    token_info = None

if not token_info:
    _LOGGER.error("Failed to get access token")

if token_info != current_token_info:
    _LOGGER.error("Got new token, store it")

Metadata

Release files for pyfireservicerota 0.0.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyfireservicerota 0.0.11
File Size Uploaded Provenance Actions
pyfireservicerota-0.0.11.tar.gz 4.2 kB Without provenance Details for pyfireservicerota-0.0.11.tar.gz

Release files / pyfireservicerota-0.0.11.tar.gz

Download URL pyfireservicerota-0.0.11.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
7ddaaa4d2e4d23ea71ae4df7dbe83aa9fbc68c9e963a252b94da04bc4bbe6d63
BLAKE2b-256 checksum
How to use checksums
e90fab6f97c1ad877aa1c8ee21927c4b3603300b182a0426702f48579dfae4ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.3

Security for pyfireservicerota 0.0.11

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.11 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page