From 15c7fa9468d75a773c8e1e41d2a7f23eb82114b2 Mon Sep 17 00:00:00 2001 From: Henry Wang Date: Tue, 7 Aug 2018 18:00:52 +0100 Subject: [PATCH] =?UTF-8?q?Add=20NAMOC=20=E4=B8=AD=E5=9B=BD=E7=BE=8E?= =?UTF-8?q?=E6=9C=AF=E9=A6=86=20--=20=E9=80=9A=E7=9F=A5=E5=85=AC=E5=91=8A?= =?UTF-8?q?=20(#429)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add NAMOC 中国美术馆 -- 通知公告 * Update docs --- README.md | 2 ++ docs/README.md | 10 ++++++ router.js | 3 ++ routes/namoc/announcement.js | 67 ++++++++++++++++++++++++++++++++++++ 4 files changed, 82 insertions(+) create mode 100644 routes/namoc/announcement.js diff --git a/README.md b/README.md index ac58aa36c..a248776a8 100644 --- a/README.md +++ b/README.md @@ -204,6 +204,8 @@ RSSHub 是一个轻量、易于扩展的 RSS 生成器,可以给任何奇奇 - 早报 - 维基百科 - 中国大陆新闻动态 +- 中国美术馆 + - 通知公告 diff --git a/docs/README.md b/docs/README.md index da35191f5..c9dcce235 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1646,3 +1646,13 @@ id, 专辑 id, 可在对应专辑页面的 URL 中找到 路由: `/wikipedia/mainland` 参数:无 + +## 中国美术馆 + +### 通知公告 + +举例: [https://rsshub.app/namoc/announcement](https://rsshub.app/namoc/announcement) + +路由: `/namoc/announcement` + +参数:无 diff --git a/router.js b/router.js index eaccc9972..165c34d7f 100755 --- a/router.js +++ b/router.js @@ -372,6 +372,9 @@ router.get('/keep/user/:id', require('./routes/keep/user')); router.get('/qidian/chapter/:id', require('./routes/qidian/chapter')); router.get('/qidian/forum/:id', require('./routes/qidian/forum')); +// 中国美术馆 +router.get('/namoc/announcement', require('./routes/namoc/announcement')); + // 懂球帝 router.get('/dongqiudi/daily', require('./routes/dongqiudi/index')); diff --git a/routes/namoc/announcement.js b/routes/namoc/announcement.js new file mode 100644 index 000000000..b529849b1 --- /dev/null +++ b/routes/namoc/announcement.js @@ -0,0 +1,67 @@ +const axios = require('../../utils/axios'); +const config = require('../../config'); +const cheerio = require('cheerio'); +const url = require('url'); + +const _axios_client = axios.create({ + headers: { + 'User-Agent': config.ua, + }, +}); + +const host = 'http://www.namoc.org/xwzx/tzgg/2017gonggao/'; + +module.exports = async (ctx) => { + const response = await _axios_client.get(host); + + const $ = cheerio.load(response.data); + + const list = $('.news-list li:not(.clearfix)').slice(0, 10); + const out = []; + const proList = []; + + for (let i = 0; i < list.length; i++) { + const $ = cheerio.load(list[i]); + const title = $('a').text(); + const itemUrl = url.resolve(host, $('a').attr('href')); + const cache = await ctx.cache.get(itemUrl); + if (cache) { + out.push(JSON.parse(cache)); + continue; + } + const single = { + title, + link: itemUrl, + guid: itemUrl, + }; + + try { + const es = _axios_client.get(itemUrl); + proList.push(es); + out.push(single); + } catch (err) { + console.log(`${title}: ${itemUrl} -- ${err.response.status}: ${err.response.statusText}`); + } + } + + const responses = await axios.all(proList); + for (let i = 0; i < responses.length; i++) { + const $ = cheerio.load(responses[i].data); + const full = $('#content'); + + out[i].description = full.find('div.Custom_UnionStyle').html(); + out[i].author = '中国美术馆'; + out[i].pubDate = new Date( + full + .find('.news-info span:last-of-type') + .text() + .replace('时间:', '') + ).toUTCString(); + ctx.cache.set(out[i].link, JSON.stringify(out[i]), 24 * 60 * 60); + } + ctx.state.data = { + title: '中国美术馆 -- 通知公告', + link: 'http://www.namoc.org/xwzx/tzgg/2017gonggao/', + item: out, + }; +};