Created
February 4, 2018 21:23
-
-
Save kyv/d7870d3f6c2d959a63427a3b12106733 to your computer and use it in GitHub Desktop.
news actuator
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
import { sampleSize, difference } from 'lodash'; | |
import { parseString } from 'xml2js'; | |
import { | |
HTTP, | |
} from 'meteor/http'; | |
const rssUrl = 'https://www.rindecuentas.org/tag/torre-de-control/feed/'; | |
function nameToLowerCase(name){ | |
return name.toLowerCase(); | |
} | |
export function news(id, collection) { | |
const oldNews = collection.news(); | |
const newNews = requestNews(); | |
const diff = difference(oldNews, newNews); | |
diff.forEach((o) => (NewsCollection.insert(o))); | |
} | |
export function requestNews() { | |
HTTP.get(rssUrl, (error, result) => { | |
parseString(result.content, { | |
trim: true, | |
normalize: true, | |
// valueProcessors: [nameToLowerCase], | |
}, (err, data) => { | |
const items = data.rss.channel[0].item; | |
const eles = cy.elements('node'); | |
const sample = sampleSize(eles.jsons(), 6); | |
items.forEach((o, i) => { | |
const sE = sample[i]; | |
console.log(sE); | |
const edge = { | |
group: 'edges', | |
data: { | |
id: `${sE.data.id}-torre-${i}`, | |
source: sE.data.id, | |
target: `torre-${i}`, | |
label: 'nota', | |
} | |
}; | |
const e = [{ | |
group: 'nodes', | |
classes: 'torre-de-control', | |
data: { | |
id: `torre-${i}`, | |
name: o.title, | |
link: o.link, | |
} | |
}, edge]; | |
cy.add(e); | |
}); | |
}); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment