Last active
December 28, 2015 04:19
-
-
Save zdavkeos/7441275 to your computer and use it in GitHub Desktop.
Python script to download and convert Xcel Energy's current outage data
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
#!/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