PolarizedIons / eskom-loadshedding-api

Basic (in-progress) api to expose the eskom endpoints for loadshedding.

Home Page:https://www.npmjs.com/package/eskom-loadshedding-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Eskom Loadshedding API

Dependencies Downloads Licence Version

A basic (in-progress) api to expose the Eskom loadshedding endpoints. Typescript ready!

Usage / Examples

Get the current status

import { Status, LoadsheddingStage } from 'eskom-loadshedding-api';

Status.getStatus().then((status: LoadsheddingStage) => console.log('Current status: ', status));

Check if currently loadshedding

import { Status, LoadsheddingStage } from 'eskom-loadshedding-api';

Status.getStatus().then((status) => console.log('Is currently loadshedding?', status !== LoadsheddingStage.NOT_LOADSHEDDING));

Search for municipalities

import { Search, Province, Municipality } from 'eskom-loadshedding-api';

Search.getMunicipalities(Province.WESTERN_CAPE).then((municipalities: Municipality[]) =>
    console.log(
        'Western Cape municipalities:',
        municipalities.map((el: Municipality) => el.name)
    )
);

Search for suburbs in municipalities

import { Search, Suburb } from 'eskom-loadshedding-api';

Search.getMunicipalitySuburbs(336 /* Beauford West's id */, 'Aard' /* Search term */).then((suburbs: Suburb[]) => console.log('Filterd suburbs in Beaufort West:', suburbs));

Search for suburbs in SA

import { Search, SearchSuburb } from 'eskom-loadshedding-api';

Search.searchSuburbs('Ashton').then((results: SearchSuburb[]) => console.log('Searching for "Ashton":', results));

Get Schedule for suburb

import { LoadsheddingStage, LoadsheddingSchedule, Schedule } from 'eskom-loadshedding-api';

Schedule.getSchedule(62648 /* Beeldhoursfontein, Beauford West */, LoadsheddingStage.STAGE_1).then((schedule: LoadsheddingSchedule) => console.log(JSON.stringify(schedule, null, 4)));

Schedule.getFullSchedule(62648).then((schedules: LoadsheddingSchedule[]) => console.log(JSON.stringify(schedules, null, 4)));

Methods

Status

  • Status.getStatus(): Promise<LoadsheddingStage>;

Search

  • Search.getMunicipalities(province: Province): Promise<Municipality[]>;
  • Search.getMunicipalitySuburbs(municipalityId: number, searchTerm: string = '', pageNum: number = 1): Promise<Suburb[]>;
  • Search.searchSuburbs(searchTerm: string, maxResults: number = 300): Promise<SearchSuburb[]>;

Schedule

  • Schedule.getSchedule(suburbId: number, stage: LoadsheddingStage): Promise<LoadsheddingSchedule>;
  • Schedule.getFullSchedule(suburbId: number): Promise<LoadsheddingSchedule[]>;

Models

Municipality

class Municipality {
    public id: number;
    public name: string;
}

Suburb

class Suburb {
    public id: number;
    public name: string;
    public total: number;
}

Search Suburb

class SearchSuburb {
    municipality: string;
    province: string;
    suburb: string;
    id: number;
    total: number;
}

Schedule

interface LoadsheddingSchedule {
    schedule: ScheduleDay[];
}

interface ScheduleDay {
    day: Date;
    times: ScheduleTime[];
}

interface ScheduleTime {
    startTime: Date;
    endTime: Date;
}

Enums

Loadshedding Stage

enum LoadsheddingStage {
    UNKNOWN = -1,
    NOT_LOADSHEDDING = 0,
    STAGE_1 = 1,
    STAGE_2 = 2,
    STAGE_3 = 3,
    STAGE_4 = 4,
    STAGE_5 = 5,
    STAGE_6 = 6,
    STAGE_7 = 7,
    STAGE_8 = 8,
}

Province

enum Province {
    EASTERN_CAPE = 1,
    FREE_STATE = 2,
    GAUTENG = 3,
    KWAZULU_NATAL = 4,
    LIMPOPO = 5,
    MPUMALANGA = 6,
    NORTH_WEST = 7,
    NORTHERN_CAPE = 8,
    WESTERN_CAPE = 9,
}

About

Basic (in-progress) api to expose the eskom endpoints for loadshedding.

https://www.npmjs.com/package/eskom-loadshedding-api


Languages

Language:TypeScript 100.0%