Skip to content

Instantly share code, notes, and snippets.

@incanus
Created December 5, 2011 23:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save incanus/1435907 to your computer and use it in GitHub Desktop.
Save incanus/1435907 to your computer and use it in GitHub Desktop.
Script to scrape outage data from Connecticut Light & Power data site at http://outage.cl-p.com/outage/mobile.aspx for use in maps at http://tiles.mapbox.com/justin during November 2011 mass outages. Maps made with http://mapbox.com/tilemill/
#!/bin/sh
DATEFILE=/tmp/`date +"%s"`.html
curl -s http://outage.cl-p.com/outage/mobile.aspx > $DATEFILE
rm outages.csv 2>/dev/null
#cat $DATEFILE | grep '<table' | sed -e 's/.*<thead><tr><th>//g' -e 's/<\/th><\/tr><\/thead>.*//g' -e 's/<\/th><th>/,/g' >> outages.csv
cat $DATEFILE | grep '<table' | sed -e 's/.*<\/thead>//g' -e 's/<tfoot>.*//g' -e 's/<tr><td>//g' -e 's/<\/td><td>/|/g' -e 's/<\/td><\/tr>/@/g' -e 's/@$//g' | tr '@' "\n" >> outages.csv
rm $DATEFILE
rm outages.sqlite 2>/dev/null
sqlite3 outages.sqlite 'CREATE TABLE outages (town STRING, total_customers INTEGER, customers_out INTEGER, percent_out INTEGER);'
sqlite3 outages.sqlite '.import outages.csv outages'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment