45 lines
1.2 KiB
JavaScript
45 lines
1.2 KiB
JavaScript
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){
|
|
return parser.parseURL(url).then(feed=>feed.items).then(items=>{
|
|
let idx = items.findIndex(i => parseInt(i.guid) === min_id);
|
|
if(idx>=0) return items.slice(0,idx).reverse();
|
|
else return items.reverse();
|
|
});
|
|
}
|
|
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}`);
|
|
}));
|