feat: add 網路天文館天象預報 (#6480)
This commit is contained in:
@@ -1655,6 +1655,12 @@ column 为 third 时可选的 category:
|
||||
|
||||
</Route>
|
||||
|
||||
## 網路天文館
|
||||
|
||||
### 天象預報
|
||||
|
||||
<Route author="nczitzk" example="/tam/forecast" path="/tam/forecast"/>
|
||||
|
||||
## 网易号
|
||||
|
||||
### 更新
|
||||
|
||||
@@ -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'));
|
||||
|
||||
|
||||
@@ -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(/<label>公告日期 : <\/label> (\d{4}-\d{2}-\d{2})/)[1]).toUTCString();
|
||||
|
||||
return item;
|
||||
})
|
||||
)
|
||||
);
|
||||
|
||||
ctx.state.data = {
|
||||
title: $('title').text(),
|
||||
link: currentUrl,
|
||||
item: items,
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user