Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@JonathanMH
Created November 8, 2015 23:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JonathanMH/beb9565a26d3e5cd3526 to your computer and use it in GitHub Desktop.
Save JonathanMH/beb9565a26d3e5cd3526 to your computer and use it in GitHub Desktop.
XML parsing and filtering
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){
});
});
});
{
"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