From 405caf5fadfa2be11cb7d0a7961576d0b9980eb0 Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 24 Dec 2020 01:36:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E7=B6=B2=E8=B7=AF=E5=A4=A9?= =?UTF-8?q?=E6=96=87=E9=A4=A8=E5=A4=A9=E8=B1=A1=E9=A0=90=E5=A0=B1=20(#6480?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/new-media.md | 6 +++++ lib/router.js | 4 +++ lib/routes/tam/forecast.js | 54 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 lib/routes/tam/forecast.js diff --git a/docs/new-media.md b/docs/new-media.md index 1c91abba0..00cdb1e64 100644 --- a/docs/new-media.md +++ b/docs/new-media.md @@ -1655,6 +1655,12 @@ column 为 third 时可选的 category: +## 網路天文館 + +### 天象預報 + + + ## 网易号 ### 更新 diff --git a/lib/router.js b/lib/router.js index 680f013f8..36447f863 100644 --- a/lib/router.js +++ b/lib/router.js @@ -3724,8 +3724,12 @@ router.get('/mathunion/fields-medal', require('./routes/mathunion/fields-medal') // ACM router.get('/acm/amturingaward', require('./routes/acm/amturingaward')); +// 網路天文館 +router.get('/tam/forecast', require('./routes/tam/forecast')); + // Day One router.get('/dayone/blog', require('./routes/dayone/blog')); + // 滴答清单 router.get('/dida365/habit/checkins', require('./routes/dida365/habit-checkins')); diff --git a/lib/routes/tam/forecast.js b/lib/routes/tam/forecast.js new file mode 100644 index 000000000..74165a3ba --- /dev/null +++ b/lib/routes/tam/forecast.js @@ -0,0 +1,54 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const rootUrl = 'https://www.tam.museum'; + const currentUrl = `${rootUrl}/astronomy/forecast.php?lang=tw`; + const response = await got({ + method: 'get', + url: currentUrl, + https: { + rejectUnauthorized: false, + }, + }); + + const $ = cheerio.load(response.data); + + const list = $('#sample_2 a[title]') + .slice(0, 10) + .map((_, item) => { + item = $(item); + return { + title: item.text(), + link: `${rootUrl}/astronomy/${item.attr('href')}`, + }; + }) + .get(); + + const items = await Promise.all( + list.map( + async (item) => + await ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got({ + method: 'get', + url: item.link, + https: { + rejectUnauthorized: false, + }, + }); + const content = cheerio.load(detailResponse.data); + + item.description = content('.content_detail').html(); + item.pubDate = new Date(detailResponse.data.match(/