-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(route): migrate nmc weatheralarm (#14624)
- Loading branch information
Showing
7 changed files
with
70 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/weatheralarm/:province?': ['ylc395'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module.exports = { | ||
'nmc.cn': { | ||
_name: '中央气象台', | ||
'.': [ | ||
{ | ||
title: '全国气象预警', | ||
docs: 'https://docs.rsshub.app/routes/forecast#zhong-yang-qi-xiang-tai', | ||
source: ['/publish/alarm.html', '/'], | ||
target: '/nmc/weatheralarm', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default (router) => { | ||
router.get('/weatheralarm/:province?', './weatheralarm'); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import cache from '@/utils/cache'; | ||
import got from '@/utils/got'; | ||
import { parseDate } from '@/utils/parse-date'; | ||
import timezone from '@/utils/timezone'; | ||
import * as cheerio from 'cheerio'; | ||
|
||
export default async (ctx) => { | ||
const { province } = ctx.req.param(); | ||
const alarmInfoURL = `http://www.nmc.cn/rest/findAlarm`; | ||
const { data: response } = await got(alarmInfoURL, { | ||
searchParams: { | ||
pageNo: 1, | ||
pageSize: 20, | ||
signaltype: '', | ||
signallevel: '', | ||
province, | ||
}, | ||
}); | ||
|
||
const list = response.data.page.list.map((item) => ({ | ||
title: item.title, | ||
link: `http://www.nmc.cn${item.url}`, | ||
pubDate: timezone(parseDate(item.issuetime), 8), | ||
})); | ||
|
||
const items = await Promise.all( | ||
list.map((item) => | ||
cache.tryGet(item.link, async () => { | ||
const { data: response } = await got(item.link); | ||
const $ = cheerio.load(response); | ||
|
||
item.description = | ||
$('#icon').html() + | ||
$('#alarmtext') | ||
.toArray() | ||
.map((i) => $(i).html()) | ||
.join(''); | ||
|
||
return item; | ||
}) | ||
) | ||
); | ||
|
||
ctx.set('data', { | ||
title: '中央气象台全国气象预警', | ||
link: 'http://www.nmc.cn/publish/alarm.html', | ||
item: items, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters