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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/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