Created
December 5, 2011 23:31
-
-
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/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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