Skip to content

Instantly share code, notes, and snippets.

@kyv
Created February 4, 2018 21:23
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 kyv/d7870d3f6c2d959a63427a3b12106733 to your computer and use it in GitHub Desktop.
Save kyv/d7870d3f6c2d959a63427a3b12106733 to your computer and use it in GitHub Desktop.
news actuator
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