2020-07-02 20:04:32 +02:00
|
|
|
const Parser = require('rss-parser');
|
|
|
|
const parser = new Parser();
|
|
|
|
|
|
|
|
const ORG = {
|
|
|
|
CH : 1,
|
|
|
|
BR: 1070,
|
|
|
|
EDI: 301,
|
|
|
|
BAG : 317,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const base_url = 'https://www.newsd.admin.ch/newsd/feeds/rss';
|
|
|
|
//https://www.news.admin.ch/dienstleistungen/00008/00131/00146/index.html?lang=fr&rss-id=1_35
|
|
|
|
const get_url = function(opts){
|
|
|
|
const lang = opts.lang || 'de';
|
|
|
|
const org_nr = opts.org || '301';
|
|
|
|
const offer_nr = opts.offer || '';
|
|
|
|
const topic = opts.topic || '';
|
|
|
|
const sdate = opts.sdate || opts.since || '-1';
|
|
|
|
const edate = opts.edate || '';
|
|
|
|
const kind = opts.kind || 'M';//M,R,...
|
|
|
|
return base_url+'?'+
|
|
|
|
'&lang='+lang+
|
|
|
|
'&org-nr='+org_nr+
|
|
|
|
'&topic='+topic+
|
|
|
|
//'&keyword='+
|
|
|
|
'&offer-nr='+offer_nr+
|
|
|
|
//'&catalogueElement='+
|
|
|
|
'&kind='+kind+
|
|
|
|
'&start_date='+sdate+
|
|
|
|
'&end_date='+edate;
|
|
|
|
}
|
|
|
|
|
|
|
|
const get_rss = function(url,min_id){
|
2020-07-03 11:30:04 +02:00
|
|
|
return parser.parseURL(url).then(feed=>feed.items).then(items=>{
|
|
|
|
let idx = items.findIndex(i => parseInt(i.guid) === min_id);
|
2020-07-03 11:56:46 +02:00
|
|
|
console.log(idx);
|
2020-07-03 11:36:15 +02:00
|
|
|
if(idx>=0) return items.slice(0,idx).reverse();
|
|
|
|
else return items.reverse();
|
2020-07-03 11:30:04 +02:00
|
|
|
});
|
2020-07-02 20:04:32 +02:00
|
|
|
}
|
2020-07-03 11:56:46 +02:00
|
|
|
get_rss(get_url({org:ORG.BR, lang:'de',since:-3}),79718).then(r=>{
|
|
|
|
r.forEach(item=>{
|
|
|
|
console.log(`${item.title} (${item.guid}): ${item.link}`);
|
|
|
|
})
|
|
|
|
console.log(r.pop());
|
|
|
|
})
|