@curium.rocks/owm-emitter
TypeScript icon, indicating that this package has built-in type declarations

0.63.0 • Public • Published

OWM-Emitter

Security Rating Coverage Quality Gate Status

Description

This library polls the OpenWeatherMap Onecall API, detects changes, and on change, emits a event to listeners.

How to install

npm install --save @curium.rocks/owm-emitter

API Documentation

You can view the API documentation here.

Examples

Imports

import {OwmEmitter, OwmEmitterOptions, OneCallApiResponse, IDataEvent} from "@curium.rocks/owm-emitter";

Creating the options object

const owmOptions:OwmEmitterOptions = {
    id: 'your-unique-id',
    description: 'Some full text description associated to this emitter',
    name: 'your emitter name',
    checkInterval: 300000, // check for updates every 5 minutes
    appId: 'your owm app id/key',
    latitude: 0.0, // set latitude and longitude to the area you want to get weather data for
    longitude: 0.0
}

Log all alerts to console

const emitter = new OwmEmitter(owmOptions);
try {
    const listener = emitter.onData((evt: IDataEvent) => {
        const oneCallData: OneCallApiResponse = evt.data as OneCallApiResponse;
        oneCallData.alerts?.forEach((alert)=>{
            console.log(`Weather Alert: 
                         description = ${alert.description},
                         start = ${alert.start}, 
                         end = ${alert.end}, 
                         event = ${alert.event}, 
                         sender = ${alert.sender_name}`)
        });
    });
    emitter.startPolling();
} finally {
    emitter.dispose();
}

Package Sidebar

Install

npm i @curium.rocks/owm-emitter

Weekly Downloads

2

Version

0.63.0

License

MIT

Unpacked Size

20.5 kB

Total Files

14

Last publish

Collaborators

  • curium-deployer
  • akboyd88