Created
April 3, 2017 22:25
-
-
Save wilsaj/bc409ea6db702eefabf71b423eab8aff to your computer and use it in GitHub Desktop.
weather-alerts-geojson with user agent
This file contains hidden or 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
'use strict'; | |
var es = require('event-stream'); | |
var fs = require('fs'); | |
var parser = require('weather-alerts-parser'); | |
var request = require('request'); | |
var through = require('through'); | |
var geojson = require('../lib/index.js'); | |
function cleanProperties() { | |
var remove = [ | |
'geocode', | |
'parameter', | |
'polygon' | |
]; | |
return through(function write(featureCollection) { | |
featureCollection.features.forEach(function(feature) { | |
remove.forEach(function(remove) { | |
delete feature.properties[remove]; | |
}); | |
}); | |
this.queue(featureCollection); | |
}); | |
} | |
request.get({ | |
url: 'http://alerts.weather.gov/cap/us.php?x=1', | |
headers: { | |
'User-Agent': 'lol', | |
} | |
}) | |
.pipe(parser.stream()) | |
.pipe(geojson.stream({'stylize': true})) | |
.pipe(cleanProperties()) | |
.pipe(geojson.collect({'sort': true, 'flatten': true})) | |
.pipe(es.stringify()) | |
.pipe(process.stdout); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the updated gist! Much appreciated. I also thoroughly enjoy the user agent