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){
|
|
|
|
return parser.parseURL(url).then(feed=>feed.items
|
|
|
|
.sort((a, b)=>(parseInt(a.guid)-parseInt(b.guid)))
|
|
|
|
.filter((v)=>(parseInt(v.guid)>min_id)));
|
|
|
|
}
|
2020-07-02 20:45:33 +02:00
|
|
|
console.log(get_url({org:ORG.BR, lang:'de',since:-2}))
|
|
|
|
|
2020-07-02 20:04:32 +02:00
|
|
|
get_rss(get_url({org:ORG.BR, lang:'de',since:-2}),79710).then(r=>r.forEach(item=>{
|
2020-07-02 20:45:33 +02:00
|
|
|
console.log(`${item.title} (${item.guid}): ${item.link}`);
|
2020-07-02 20:04:32 +02:00
|
|
|
}));
|