Skip to content

Instantly share code, notes, and snippets.

@zdavkeos
Last active December 28, 2015 04:19
Show Gist options
  • Save zdavkeos/7441275 to your computer and use it in GitHub Desktop.
Save zdavkeos/7441275 to your computer and use it in GitHub Desktop.
Python script to download and convert Xcel Energy's current outage data
Display the source blob
Display the rendered blob
Raw
{"type": "FeatureCollection", "features": [{"geometry": {"type": "Point", "coordinates": [-93.29907999, 44.95917283]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 09:06:00 PM"}, "id": "459029"}, {"geometry": {"type": "Point", "coordinates": [-101.82587716, 35.12064424]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 10:15:00 PM"}, "id": "697610"}, {"geometry": {"type": "Point", "coordinates": [-93.3486913, 45.10713136]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 08:59:00 PM"}, "id": "282760"}, {"geometry": {"type": "Point", "coordinates": [-100.38668018, 35.91773485]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 10:54:00 PM"}, "id": "1012504"}, {"geometry": {"type": "Point", "coordinates": [-96.9618409, 43.11376719]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 10:14:00 PM"}, "id": "1664418"}, {"geometry": {"type": "Point", "coordinates": [-92.92901537, 44.81260441]}, "type": "Feature", "properties": {"onsite": true, "ert": "12-NOV-2013 07:27:00 PM"}, "id": "209134"}, {"geometry": {"type": "Point", "coordinates": [-93.06390708, 44.97157757]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 08:53:00 PM"}, "id": "478719"}, {"geometry": {"type": "Point", "coordinates": [-93.39865144, 44.87218648]}, "type": "Feature", "properties": {"onsite": true, "ert": "12-NOV-2013 08:39:00 PM"}, "id": "218100"}, {"geometry": {"type": "Point", "coordinates": [-93.21662976, 44.96975769]}, "type": "Feature", "properties": {"onsite": true, "ert": "12-NOV-2013 08:26:00 PM"}, "id": "499848"}, {"geometry": {"type": "Point", "coordinates": [-92.99076479, 45.16233699]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 02:27:15 PM"}, "id": "505615"}, {"geometry": {"type": "Point", "coordinates": [-93.14528333, 45.1063995]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 09:10:00 PM"}, "id": "515878"}, {"geometry": {"type": "Point", "coordinates": [-93.3965623, 45.03958109]}, "type": "Feature", "properties": {"onsite": true, "ert": "12-NOV-2013 07:34:00 PM"}, "id": "525338"}, {"geometry": {"type": "Point", "coordinates": [-102.57211944, 32.94270392]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 11:08:00 PM"}, "id": "2040204"}, {"geometry": {"type": "Point", "coordinates": [-93.14474384, 44.95976386]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 09:16:00 PM"}, "id": "531742"}, {"geometry": {"type": "Point", "coordinates": [-93.260797, 45.03163914]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 09:17:41 PM"}, "id": "553526"}, {"geometry": {"type": "Point", "coordinates": [-92.99245792, 44.86932335]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 05:28:00 PM"}, "id": "558030"}, {"geometry": {"type": "Point", "coordinates": [-93.26201904, 44.90815416]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 09:08:00 PM"}, "id": "570829"}, {"geometry": {"type": "Point", "coordinates": [-93.22332098, 44.93453271]}, "type": "Feature", "properties": {"onsite": true, "ert": "12-NOV-2013 08:38:00 PM"}, "id": "574022"}, {"geometry": {"type": "Point", "coordinates": [-90.18066837, 44.95268249]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 11:17:00 PM"}, "id": "1487260"}, {"geometry": {"type": "Point", "coordinates": [-101.86827801, 35.20707438]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 10:26:00 PM"}, "id": "1084612"}, {"geometry": {"type": "Point", "coordinates": [-101.86809132, 35.21295413]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 10:33:00 PM"}, "id": "1084419"}, {"geometry": {"type": "Point", "coordinates": [-105.87300619, 37.4740211]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 08:03:00 PM"}, "id": "186413"}, {"geometry": {"type": "Point", "coordinates": [-105.3925365, 40.11540398]}, "type": "Feature", "properties": {"onsite": false, "ert": "13-NOV-2013 10:00:00 AM"}, "id": "10699"}, {"geometry": {"type": "Point", "coordinates": [-105.26922043, 40.05492373]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 08:15:00 PM"}, "id": "12166"}, {"geometry": {"type": "Point", "coordinates": [-104.7941458, 39.72137311]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 08:20:00 PM"}, "id": "17833"}, {"geometry": {"type": "Point", "coordinates": [-104.96842851, 39.74915352]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 08:35:00 PM"}, "id": "15165"}, {"geometry": {"type": "Point", "coordinates": [-104.99217616, 39.7537262]}, "type": "Feature", "properties": {"onsite": true, "ert": "12-NOV-2013 07:59:04 PM"}, "id": "15306"}, {"geometry": {"type": "Point", "coordinates": [-104.89050062, 39.57725973]}, "type": "Feature", "properties": {"onsite": true, "ert": "12-NOV-2013 07:26:11 PM"}, "id": "31811"}, {"geometry": {"type": "Point", "coordinates": [-105.1446329, 39.71193694]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 07:31:00 PM"}, "id": "41705"}, {"geometry": {"type": "Point", "coordinates": [-105.14671102, 39.7110592]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 08:34:29 PM"}, "id": "24327"}, {"geometry": {"type": "Point", "coordinates": [-105.1598567, 39.7151303]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 06:45:00 PM"}, "id": "128129"}, {"geometry": {"type": "Point", "coordinates": [-104.82027847, 39.62879143]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 07:45:00 PM"}, "id": "76871"}, {"geometry": {"type": "Point", "coordinates": [-104.91045683, 39.7496329]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 06:34:00 PM"}, "id": "69480"}, {"geometry": {"type": "Point", "coordinates": [-105.00682907, 39.69433485]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 08:35:20 PM"}, "id": "77724"}, {"geometry": {"type": "Point", "coordinates": [-104.88436015, 39.62893602]}, "type": "Feature", "properties": {"onsite": false, "ert": "12-NOV-2013 11:44:00 PM"}, "id": "41220"}]}
#!/usr/bin/env python
"""
Xcel Energy power outage mapper - Simple demo of Github's mapping capabilities
This file downloads and converts Xcel's public power outage data to
GeoJSON so it can be mapped by Github.com
See it live at:
https://gist.github.com/zdavkeos/7441275
Use:
$ python xcel_outage.py > xcel_outages.geojson
Requires:
- Requests
- xmltodict
- geojson
"""
import geojson
import requests
import xmltodict
def fetch():
r = requests.get('http://www.xcelenergy.com/staticfiles/xe/Admin/javascript/XcelMappingOutagesMedia_ext.xml')
if r.status_code != 200:
return "Unable to download XML!"
c = convert(xmltodict.parse(r.text))
if not c:
return "Unable to parse XML"
return c
def convert(s):
features = []
for i in s[u'document'][u'PointsOfInterest'][u'POI']:
g = geojson.Point([float(i[u'Longitude']), float(i[u'Latitude'])])
p = {"onsite": i[u'CrewOnSite'] == u'YES', "ert":i[u'ERT']}
f = geojson.Feature(geometry=g, properties=p, id=i[u'HIDX'])
features.append(f)
return geojson.dumps(geojson.FeatureCollection(features))
if __name__ == '__main__':
print(fetch())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment