Files
RSSHub/lib/routes/ccdi/scdc.js
Chenyang Shi 38676afb73 feat: add 中央纪委国家监委审查调查 (#2614)
* feat: add 中央纪委国家监委审查调查

* no cache time


Co-authored-by: DIYgod <diy.d.god@gmail.com>
2019-07-16 11:13:28 +08:00

48 lines
1.5 KiB
JavaScript

const cheerio = require('cheerio');
const got = require('@/utils/got');
const { resolve } = require('url');
module.exports = async (ctx) => {
const url = 'http://www.ccdi.gov.cn/scdc/';
const res = await got.get(url);
const $ = cheerio.load(res.data);
const list = $('ul.list_news_dl.fixed li');
const out = await Promise.all(
list
.map(async (index, elem) => {
elem = $(elem);
const title = elem.find('a').text();
const link = resolve(url, elem.find('a').attr('href'));
const pubDate = new Date(elem.find('span').text()).toUTCString();
const item = {
title,
pubDate,
link,
};
const key = link;
const value = await ctx.cache.get(key);
if (value) {
item.description = value;
} else {
const response = await got.get(item.link);
const data = response.data;
const $ = cheerio.load(data);
item.description = $('div.TRS_Editor').html();
ctx.cache.set(key, item.description);
}
return Promise.resolve(item);
})
.get()
);
ctx.state.data = {
title: '中央纪委国家监委-审查调查',
link: url,
item: out,
};
};