A basic (in-progress) api to expose the Eskom loadshedding endpoints. Typescript ready!
import { Status, LoadsheddingStage } from 'eskom-loadshedding-api';
Status.getStatus().then((status: LoadsheddingStage) => console.log('Current status: ', status));
import { Status, LoadsheddingStage } from 'eskom-loadshedding-api';
Status.getStatus().then((status) => console.log('Is currently loadshedding?', status !== LoadsheddingStage.NOT_LOADSHEDDING));
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)
)
);
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));
import { Search, SearchSuburb } from 'eskom-loadshedding-api';
Search.searchSuburbs('Ashton').then((results: SearchSuburb[]) => console.log('Searching for "Ashton":', results));
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)));
- Status.getStatus(): Promise<LoadsheddingStage>;
- 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.getSchedule(suburbId: number, stage: LoadsheddingStage): Promise<LoadsheddingSchedule>;
- Schedule.getFullSchedule(suburbId: number): Promise<LoadsheddingSchedule[]>;
class Municipality {
public id: number;
public name: string;
}
class Suburb {
public id: number;
public name: string;
public total: number;
}
class SearchSuburb {
municipality: string;
province: string;
suburb: string;
id: number;
total: number;
}
interface LoadsheddingSchedule {
schedule: ScheduleDay[];
}
interface ScheduleDay {
day: Date;
times: ScheduleTime[];
}
interface ScheduleTime {
startTime: Date;
endTime: Date;
}
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,
}
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,
}