beyarkay / eskom-calendar

Get your loadshedding schedule in your calendar and never be left in the dark! Open-source, up-to-date, and developer friendly.
https://eskomcalendar.co.za
GNU General Public License v3.0
190 stars 35 forks source link

Auto-create a PR using Cape Town's "API" #479

Open beyarkay opened 10 months ago

beyarkay commented 10 months ago

Turns out, the cape town website's loadshedding page has an API that can be queried without needing an API key, like so:

curl 'https://d42sspn7yra3u.cloudfront.net/coct-load-shedding-extended-status.json' | jq

The result is a JSON array of all loadshedding since 2023-05-17T20:00:00. I'm not sure what's special about that date, maybe it's when the API was set up? Here's a snippet

[
  {
    "start": "2023-05-17T20:00",
    "end": "2023-05-18T05:00",
    "stage": "6"
  },
  {
    "start": "2023-05-18T05:00",
    "end": "2023-05-18T22:00",
    "stage": "3"
  },
... [336 objects omitted] ...
  {
    "start": "2023-09-21T16:00",
    "end": "2023-09-21T22:00",
    "stage": "1"
  },
  {
    "start": "2023-09-21T22:00",
    "end": "2023-09-22T05:00",
    "stage": "3"
  }
]

There's also this endpoint which can be used to check when the schedule was last updated:

curl 'https://d42sspn7yra3u.cloudfront.net/coct-load-shedding-extended-status-metadata.json'
{
  "lastUpdated": "2023-09-21T06:04:18.764+02:00"
}

Together, these endpoints could fully automate Cape Town's loadshedding via the GitHub API. This should definitely be done, and it seems like the cape town twitter feed gets manually updated based on data from the website, so the website is a better source of truth.

There's a slight problem in that there's no constant URL to historical data, so old schedules won't have any way to be verified. It's possible that this can be fixed by using the waybackmachine if they've got an API that allows programmatic saving of webpages, and then the "source" can be a web archive link. SO post 1 . SO post 2. Web archive API docs. Example saved page.