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(/