import cheerio from 'cheerio' ; import HTTPClient from './HTTPClient' ; import { LoadsheddingStage } from '../enums/LoadsheddingStage' ; import { LoadsheddingSchedule } from '../models/LoadsheddingSchedule' ; import { scheduleParser } from '../parser/ScheduleParser' ; export class Schedule extends HTTPClient { private static async getScheduleRaw ( suburbId , stage ) { const resp = await this . get ( `/GetScheduleM/${ suburbId }/${ stage }/_/1` ) ; return resp . data ; } public static async getScheduleRawHTML ( suburbId , stage ) { const html = await this . getScheduleRaw ( suburbId , stage ) ; return cheerio . load ( html ) . html ( ) ; } public static async getScheduleRawText ( suburbId , stage ) { const html = await this . getScheduleRaw ( suburbId , stage ) ; return cheerio . load ( html ) ( '#schedulem' ) . text ( ) ; } public static async getSchedule ( suburbId , stage ) { return this . getScheduleRawText ( suburbId , stage ) . then ( lines => scheduleParser ( lines ) ) ; } public static async getFullSchedule ( suburbId ) { return Promise . all ( [ this . getSchedule ( suburbId , LoadsheddingStage . STAGE_1 ) , this . getSchedule ( suburbId , LoadsheddingStage . STAGE_2 ) , this . getSchedule ( suburbId , LoadsheddingStage . STAGE_3 ) , this . getSchedule ( suburbId , LoadsheddingStage . STAGE_4 ) , ] ) ; } }