feat: add 上海市生态环境局空气质量发布 (#5011)

This commit is contained in:
Ethan Shen 2020-06-18 11:46:08 +08:00 committed by GitHub
parent f9e568433b
commit 252473c80e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 0 deletions

View File

@ -42,6 +42,12 @@ pageClass: routes
<Route author="muzea" example="/cneb/guoneinews" path="/cneb/guoneinews"/>
## 上海市生态环境局
### 空气质量
<Route author="nczitzk" example="/gov/shanghai/sthj" path="/gov/shanghai/sthj"/>
## 停电通知
### 南京市

View File

@ -2867,4 +2867,7 @@ router.get('/ems/news', require('./routes/ems/news'));
// 场库
router.get('/changku', require('./routes/changku/index'));
// 上海市生态环境局
router.get('/gov/shanghai/sthj', require('./routes/gov/shanghai/sthj'));
module.exports = router;

View File

@ -0,0 +1,26 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
module.exports = async (ctx) => {
const link = 'https://link.sthj.sh.gov.cn/aqi/index.jsp';
const response = await got({
method: 'get',
url: link,
});
const $ = cheerio.load(response.data);
const aqi = $('div.val').text();
const time = new Date().getFullYear() + '-' + $('span.t-time').eq(0).text().replace(/\s+/g, '').replace('月', '-').replace('日', ' ').replace('时', ':00:00');
ctx.state.data = {
title: '上海市生态环境局 - 空气质量',
link: link,
item: [
{
title: aqi + ' - ' + time,
link: link,
description: $('table.table').html() + $('div.air-yb').html(),
pubDate: new Date(time + ' GMT+8').toUTCString(),
},
],
};
};