Skip to content

Instantly share code, notes, and snippets.

@meandavejustice
Created August 18, 2014 00:34
Show Gist options
  • Save meandavejustice/8a63ef09bedee38f597d to your computer and use it in GitHub Desktop.
Save meandavejustice/8a63ef09bedee38f597d to your computer and use it in GitHub Desktop.
var levelup = require('level')
var db = levelup('./db', {valueEncoding: 'json'})
var getStations = require('./stations')
var getFeed = require('./feed')
var stationFile = 'podcast_directory.xml';
getStations(stationFile, function(err, stations) {
if (err) console.log('ERR: putting getting stations')
db.put('stations', stations, function (err) {
if (err) return console.log('ERROR: writing stationlist', err);
db.get('stations', function(err, value) {
if (err) console.log('ERR: putting getting stations')
stations = value;
stations.forEach(function(station) {
if (!station.xmlUrl) return;
var xmlURL = station.xmlUrl;
if (!!~xmlURL.indexOf('feed://')) {
xmlURL = xmlURL.replace(/feed:\/\//, 'http://')
} else if (xmlURL.indexOf('.xml') === -1) {
xmlURL = xmlURL +='.xml';
}
if (xmlURL.indexOf('http://') === -1) {
xmlURL = 'http://' + xmlURL;
}
getFeed(xmlURL, function(err, value) {
if (err) console.log('ERROR: ', err);
if (station.title) {
db.put(station.title, value, function(err) {
if (err) console.log('err writing shows for ', station.title)
});
}
});
});
})
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment