A Simple WMECO Outage Page

Those of you who live in the Pioneer Valley know that we have a decent amount of power outages. Our power company WMECO has a nice outage map – but that's a big page to load when you're looking on your phone – obviously your computer isn't working in a power outage. Also, for me anyway, the map doesn't load on my android phone. But even if it did, I would prefer a light page – a list of towns with outage information is enough for me.

WMECO's map uses jQuery to hit a couple ASP pages on their servers to pull the outage data. I reverse-engineered the calls, and re-did them in PHP. This was actually a pain, mostly because using curl in PHP is new to me, and ASP is really particular about the parameters it wants. Anyway, here's my short and concise outage page, and below is the code used to build it.

 1
 2function load_outage_data() {
 3  $url = "http://www.wmeco.com/outage/services/OutageData.asmx/AllOutageData";
 4
 5  //open connection
 6  $ch = curl_init();
 7
 8  //set the url, number of POST vars, POST data
 9  curl_setopt($ch,CURLOPT_URL, $url);
10  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
11  curl_setopt($ch,CURLOPT_POST,true);
12  curl_setopt($ch,CURLOPT_POSTFIELDS,"{}");
13  curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
14 
15  //execute post
16  $result = curl_exec($ch);
17
18  //close connection
19  curl_close($ch);
20
21  $result = json_decode($result);
22
23  return $result->d;
24} // load_outage_data
25
26
27$outages = load_outage_data();
28
29print "<ul>\n";
30foreach($outages as $outage) {
31  print "<li>" . $outage->Name . ": " . 
32        $outage->CustomersAffected . "/" .
33        $outage->NumberOfCustomersServed . " (" .
34        $outage->PercentageCustomersAffected . "%)</li>\n";
35}
36print "</ul>\n";
37
Filed under: Code, php, weather