From 252473c80e7b404f911fcda02782e76d594bc07d Mon Sep 17 00:00:00 2001 From: Ethan Shen Date: Thu, 18 Jun 2020 11:46:08 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20add=20=E4=B8=8A=E6=B5=B7=E5=B8=82?= =?UTF-8?q?=E7=94=9F=E6=80=81=E7=8E=AF=E5=A2=83=E5=B1=80=E7=A9=BA=E6=B0=94?= =?UTF-8?q?=E8=B4=A8=E9=87=8F=E5=8F=91=E5=B8=83=20(#5011)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/forecast.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/gov/shanghai/sthj.js | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+) create mode 100644 lib/routes/gov/shanghai/sthj.js diff --git a/docs/forecast.md b/docs/forecast.md index cea9fb737..32f74aeaa 100644 --- a/docs/forecast.md +++ b/docs/forecast.md @@ -42,6 +42,12 @@ pageClass: routes +## 上海市生态环境局 + +### 空气质量 + + + ## 停电通知 ### 南京市 diff --git a/lib/router.js b/lib/router.js index 4372e7750..65f4287b7 100644 --- a/lib/router.js +++ b/lib/router.js @@ -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; diff --git a/lib/routes/gov/shanghai/sthj.js b/lib/routes/gov/shanghai/sthj.js new file mode 100644 index 000000000..0b71ceb5b --- /dev/null +++ b/lib/routes/gov/shanghai/sthj.js @@ -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(), + }, + ], + }; +};