Created
November 8, 2015 23:12
-
-
Save JonathanMH/beb9565a26d3e5cd3526 to your computer and use it in GitHub Desktop.
XML parsing and filtering
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
var request = require('request'); | |
var async = require('async'); | |
var xml2js = require('xml2js'); | |
var parseString = require('xml2js').parseString; | |
var parser = new xml2js.Parser( | |
{ | |
preserveChildrenOrder: true, | |
explicitArray: false, | |
charkey: "content", | |
attrkey: "props", | |
childkey: "content", | |
emptyTag: {} | |
} | |
); | |
var _ = require('lodash'); | |
var url = "https://kwerfeldein.de/feed/"; | |
var isCategory = function(mixed, searchTerm){ | |
if(mixed.constructor == Array){ | |
if(mixed.indexOf(searchTerm) != -1){ | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
else { | |
if (mixed == searchTerm){ | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
} | |
request(url, function (error, response, body) { | |
parser.parseString(body, function(err, result){ | |
// console.log(result.rss.channel); | |
async.each(result.rss.channel.item, function(entry, callback){ | |
//console.log(entry.title, entry.category); | |
if(isCategory(entry.category, 'Ausblick') || isCategory(entry.category, 'ausblick')){ | |
console.log(entry.title, entry.link); | |
callback(null); | |
} | |
else { | |
callback(null); | |
} | |
}, function(err, result){ | |
}); | |
}); | |
}); |
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
{ | |
"name": "rss", | |
"version": "1.0.0", | |
"description": "", | |
"main": "get-xml.js", | |
"dependencies": { | |
"async": "^1.5.0", | |
"lodash": "^3.10.1", | |
"request": "^2.65.0", | |
"xml2js": "^0.4.15" | |
}, | |
"devDependencies": {}, | |
"scripts": { | |
"test": "echo \"Error: no test specified\" && exit 1" | |
}, | |
"author": "", | |
"license": "ISC" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment