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.

function load_outage_data() {
  $url = "http://www.wmeco.com/outage/services/OutageData.asmx/AllOutageData";

  //open connection
  $ch = curl_init();

  //set the url, number of POST vars, POST data
  curl_setopt($ch,CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
  //execute post
  $result = curl_exec($ch);

  //close connection

  $result = json_decode($result);

  return $result->d;
} // load_outage_data

$outages = load_outage_data();

print "<ul>\n";
foreach($outages as $outage) {
  print "<li>" . $outage->Name . ": " . 
	$outage->CustomersAffected . "/" .
	$outage->NumberOfCustomersServed . " (" .
	$outage->PercentageCustomersAffected . "%)</li>\n";
print "</ul>\n";

Filed under: Code, php, weather