Loadshedding API for Ethekweni municipality

ADrunkTeddyBear

Expert Member
Joined
Jul 22, 2014
Messages
1,825
Reaction score
1,323
Location
Durban
Hi guys. Has anyone created an API to return the times and loadshedding status of Ethekweni?

TIA
 
Loadshedding notifier or Eskom se push??
 
As in whether load shedding? You can probably get away with just getting Eskom direct currently, don't they follow normal Eskom for now?


Does Ethekweni have it on their site? Can probably query endpoint directly, just be sure to limit to like once every few minutes.
 
As in whether load shedding? You can probably get away with just getting Eskom direct currently, don't they follow normal Eskom for now?


Does Ethekweni have it on their site? Can probably query endpoint directly, just be sure to limit to like once every few minutes.
I can try the query and see if that works every 10 mins
 
I wrote this quick to check start time of loadshedding today, but if you know how to write bash/linux scripts you can set it to replace the date grep dynamically.

Check https://mybroadband.co.za/forum/threads/loadshedding-api.672196/page-2 to fix the URL with your province and municipality.

It is a bit dirty at the end maybe but just wrote it quickly to check.
Will need to set it to check today and a day ahead if the time is like mine today 00:00, so script will be allot bigger in the end with conditions. or maybe a separate script/cron for 23:40 daily to check next day already, if time 00:00 again.

Will update later sometime to compare time with actual and shutdown if time less 10min or something for my server that does not fit on my UPS/inverter.

#check/record loadshedding level
export loadslvl="$(expr `curl -sL http://loadshedding.eskom.co.za/LoadShedding/GetStatus` - 1)"
#create URL for curl to use
export loadsurl="http://loadshedding.eskom.co.za/LoadShedding/GetScheduleM/1069114/$(echo $loadslvl)/9/1"

#get time for loadshedding on the day, could be 3 times, will check tomorrow if it works and how i can use multiple times for shutdown, also hard coded to 6 Nov for now
curl -sL `echo $loadsurl` | grep -A7 "06 Nov" | awk -F"Time" '{print $2}' | sed 's/\":\"//g' | sed 's/ - .*//g' | grep -v "^$"

Output:
00:00
 
Script updated
Seems a bit buggy with the URL so maybe run twice before the hour.
Currently just echos shutdown

#!/bin/bash
#Check loadsshedding level
export loadslvl="$(expr `curl -sL http://loadshedding.eskom.co.za/LoadShedding/GetStatus` - 1)"
#If level less than 1 exit
if [[ $loadslvl -lt 1 ]]; then exit ; fi
#Make URL
export loadsurl="http://loadshedding.eskom.co.za/LoadShedding/GetScheduleM/1069114/$(echo $loadslvl)/9/1"
#Set today date unless if hour 23:?? set date tomorrow
date +"%H" | grep 23 > /dev/null && export loadsdate=`date +'%d %b' -d "$send_date+1 days"` || export loadsdate=`date +'%d %b'`
#Check times, try again if fails (return nothing)
curl -sL `echo $loadsurl` | awk "/$(echo $loadsdate)/,/scheduleDay/" | sed 's/.*Time\":\"//g' | sed 's/ - .*//g' | grep "^[0-9]" > loadstimes.txt || \
sleep 5 && curl -sL `echo $loadsurl` | awk "/$(echo $loadsdate)/,/scheduleDay/" | sed 's/.*Time\":\"//g' | sed 's/ - .*//g' | grep "^[0-9]" > loadstimes.txt
#check actual time +1 with loadsheeding times, echo shutdown or no_loadshedding_next_hour
cat loadstimes.txt | while read times ; do echo $times | awk -F: '{ print $1 }' | grep `date +"%H" -d "$send_date+1hour"` > /dev/null && echo shutdown || echo no_loadshedding_next_hour ; done

updated to hide hour grep if 23
updated to awk only hour at the end, or hour 00 picks up minutes on both as shutdown

./checkloadstimes.sh ; date
shutdown
no_loadshedding_next_hour
Sat 06 Nov 2021 23:16:42 SAST

./checkloadstimes.sh ; date
no_loadshedding_next_hour
shutdown
Sun 07 Nov 2021 07:32:20 SAST

cat loadstimes.txt
00:00
08:00
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X