From cb210c8c723d3bd4f5d8d8de43c66c91caf60a5c Mon Sep 17 00:00:00 2001 From: CaoMeiYouRen <40430746+CaoMeiYouRen@users.noreply.github.com> Date: Mon, 19 Dec 2022 19:45:32 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20=E6=96=B0=E5=A2=9E=20=E8=85=BE?= =?UTF-8?q?=E8=AE=AF=E6=96=B0=E9=97=BB=20-=20=E6=96=B0=E5=9E=8B=E5=86=A0?= =?UTF-8?q?=E7=8A=B6=E7=97=85=E6=AF=92=E8=82=BA=E7=82=8E=E7=96=AB=E6=83=85?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E8=BF=BD=E8=B8=AA=20(#11467)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): 添加 百度股市通 * fix: 修改 百度股市通 路径 * docs: 添加 百度股市通 文档 * feat: 添加 radar 支持 * fix: 按字母顺序插入新路由 * feat(route): 新增 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 * fix: 优化 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 的标题 * fix: 修复 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 部分情况下的非空判断 * fix: 修复 地区名称标题的问题 * fix: 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 的 guid 增加 pubDate * fix: 修复 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 guid 中添加 pubDate * fix: 修改 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 的 title --- docs/other.md | 12 ++++ lib/v2/tencent/maintainer.js | 2 + lib/v2/tencent/news/coronavirus/data.js | 71 +++++++++++++++++++ lib/v2/tencent/news/coronavirus/total.js | 34 +++++++++ lib/v2/tencent/news/coronavirus/utils.js | 17 +++++ lib/v2/tencent/radar.js | 8 +++ lib/v2/tencent/router.js | 2 + .../templates/coronavirus/chinaTotal.art | 6 ++ lib/v2/tencent/templates/coronavirus/data.art | 4 ++ 9 files changed, 156 insertions(+) create mode 100644 lib/v2/tencent/news/coronavirus/data.js create mode 100644 lib/v2/tencent/news/coronavirus/total.js create mode 100644 lib/v2/tencent/news/coronavirus/utils.js create mode 100644 lib/v2/tencent/templates/coronavirus/chinaTotal.art create mode 100644 lib/v2/tencent/templates/coronavirus/data.art diff --git a/docs/other.md b/docs/other.md index c3a8f8d6e1..af25d2bfd9 100644 --- a/docs/other.md +++ b/docs/other.md @@ -806,6 +806,18 @@ type 为 all 时,category 参数不支持 cost 和 free +### 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪 + +数据来源: + +#### 中国本土数据统计 + + + +#### 省市疫情数据 + + + ### South China Morning Post - China coronavirus outbreak diff --git a/lib/v2/tencent/maintainer.js b/lib/v2/tencent/maintainer.js index 912c121af9..6fa25e9c21 100644 --- a/lib/v2/tencent/maintainer.js +++ b/lib/v2/tencent/maintainer.js @@ -1,5 +1,7 @@ module.exports = { '/cloud/column/:id?/:tag?': ['nczitzk'], + '/news/coronavirus/data/:province?/:city?': ['CaoMeiYouRen'], + '/news/coronavirus/total': ['CaoMeiYouRen'], '/pvp/newsindex/:type': ['Jeason0228', 'HenryQW'], '/qq/sdk/changelog/:platform': ['nuomi1'], }; diff --git a/lib/v2/tencent/news/coronavirus/data.js b/lib/v2/tencent/news/coronavirus/data.js new file mode 100644 index 0000000000..c5c28777c4 --- /dev/null +++ b/lib/v2/tencent/news/coronavirus/data.js @@ -0,0 +1,71 @@ +const { getData } = require('./utils'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const province = ctx.params.province || ''; + const city = ctx.params.city || ''; + + const link = 'https://news.qq.com/zt2020/page/feiyan.htm#/'; + const item = []; + + const diseaseh5Shelf = (await getData(['diseaseh5Shelf']))?.data?.diseaseh5Shelf || {}; + const { lastUpdateTime, areaTree } = diseaseh5Shelf; + const nationalData = areaTree?.[0]; + const provinceList = nationalData?.children; + + let todayConfirm = 0; + let totalNowConfirm = 0; + let totalConfirm = 0; + let totalDead = 0; + let coronavirusData = {}; + let placeName = ''; + + if (!province || province === '中国' || province === '全国') { + // 没有传参则取全国 + coronavirusData = nationalData; + placeName = '中国'; + } else { + // 分省份获取 + coronavirusData = provinceList?.find((e) => e.name === province); + placeName = province; + if (city) { + // 继续获取 区县 数据 + coronavirusData = coronavirusData?.children?.find((e) => e.name === city); + if (coronavirusData) { + placeName = `${province}-${city}`; + } + } + } + if (!coronavirusData) { + throw new Error(`未找到 ${placeName} 的疫情数据,请检查输入的省市名称是否正确`); + } + todayConfirm = coronavirusData.today?.confirm; + totalNowConfirm = coronavirusData.total?.nowConfirm; + totalConfirm = coronavirusData.total?.confirm; + totalDead = coronavirusData.total?.dead; + const pubDate = parseDate(coronavirusData.total?.mtime || lastUpdateTime); + + const title = `${placeName} - 腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪`; + + const info = { + title: `${placeName} - 疫情数据`, + description: art(path.join(__dirname, '../../templates/coronavirus/data.art'), { + todayConfirm, + totalNowConfirm, + totalConfirm, + totalDead, + }), + pubDate, + guid: `${link}${placeName}?pubDate=${pubDate.toISOString()}`, + }; + + item.push(info); + + ctx.state.data = { + title, + link, + item, + }; +}; diff --git a/lib/v2/tencent/news/coronavirus/total.js b/lib/v2/tencent/news/coronavirus/total.js new file mode 100644 index 0000000000..08c10f2334 --- /dev/null +++ b/lib/v2/tencent/news/coronavirus/total.js @@ -0,0 +1,34 @@ +const { getData } = require('./utils'); +const { parseDate } = require('@/utils/parse-date'); +const { art } = require('@/utils/render'); +const path = require('path'); + +module.exports = async (ctx) => { + const title = '腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪'; + const link = 'https://news.qq.com/zt2020/page/feiyan.htm#/'; + const item = []; + + const chinaTotal = (await getData(['diseaseh5Shelf']))?.data?.diseaseh5Shelf?.chinaTotal || {}; + const { localConfirmH5, localWzzAdd, confirmAdd, localConfirm, nowLocalWzz, highRiskAreaNum, mtime } = chinaTotal; + const pubDate = parseDate(mtime); + const info = { + title: '中国本土数据统计', + description: art(path.join(__dirname, '../../templates/coronavirus/chinaTotal.art'), { + localConfirmH5, + localWzzAdd, + confirmAdd, + localConfirm, + nowLocalWzz, + highRiskAreaNum, + }), + pubDate, + guid: `${link}total?pubDate=${pubDate.toISOString()}`, + }; + item.push(info); + + ctx.state.data = { + title, + link, + item, + }; +}; diff --git a/lib/v2/tencent/news/coronavirus/utils.js b/lib/v2/tencent/news/coronavirus/utils.js new file mode 100644 index 0000000000..ccdd18d8f6 --- /dev/null +++ b/lib/v2/tencent/news/coronavirus/utils.js @@ -0,0 +1,17 @@ +const got = require('@/utils/got'); + +/** + * + * + * @author CaoMeiYouRen + * @date 2022-12-18 + * @param {string[]} [modules=[]] localCityNCOVDataList,diseaseh5Shelf,nowConfirmStatis,provinceCompare,FAutoforeignList,FAutoCountryConfirmAdd,WomWorld,WomAboard,VaccineTopData + */ +const getData = async (modules = []) => { + const response = await got('https://api.inews.qq.com/newsqa/v1/query/inner/publish/modules/list?modules=' + modules.join(',')); + return response.data; +}; + +module.exports = { + getData, +}; diff --git a/lib/v2/tencent/radar.js b/lib/v2/tencent/radar.js index cb806a3286..6fd8cab0e6 100644 --- a/lib/v2/tencent/radar.js +++ b/lib/v2/tencent/radar.js @@ -27,6 +27,14 @@ module.exports = { target: (params, url) => `/wechat/mp/msgalbum/${new URL(url).searchParams.get('__biz')}/${new URL(url).searchParams.get('album_id')}`, }, ], + news: [ + { + title: '腾讯新闻 - 新型冠状病毒肺炎疫情实时追踪', + docs: 'https://docs.rsshub.app/other.html#xin-guan-fei-yan-yi-qing-xin-wen-dong-tai', + source: ['/zt2020/page/feiyan.htm#/'], + target: '/tencent/news/coronavirus/total', + }, + ], pvp: [ { title: '王者荣耀 - 新闻中心', diff --git a/lib/v2/tencent/router.js b/lib/v2/tencent/router.js index fc686be3eb..cec464ac11 100644 --- a/lib/v2/tencent/router.js +++ b/lib/v2/tencent/router.js @@ -1,5 +1,7 @@ module.exports = (router) => { router.get('/cloud/column/:id?/:tag?', require('./cloud/column')); + router.get('/news/coronavirus/data/:province?/:city?', require('./news/coronavirus/data')); + router.get('/news/coronavirus/total', require('./news/coronavirus/total')); router.get('/pvp/newsindex/:type', require('./pvp/newsindex')); router.get('/qq/sdk/changelog/:platform', require('./qq/sdk/changelog')); }; diff --git a/lib/v2/tencent/templates/coronavirus/chinaTotal.art b/lib/v2/tencent/templates/coronavirus/chinaTotal.art new file mode 100644 index 0000000000..63fb5b0ea8 --- /dev/null +++ b/lib/v2/tencent/templates/coronavirus/chinaTotal.art @@ -0,0 +1,6 @@ +

本土确诊:

+{{@localConfirmH5}}


+

本土无症状:

+{{@localWzzAdd}}


+

确诊病例:

+{{@confirmAdd}}


+

现有本土确诊:

{{@localConfirm}}


+

现有本土无症状:

{{@nowLocalWzz}}


+

高风险地区:

{{@highRiskAreaNum}}


diff --git a/lib/v2/tencent/templates/coronavirus/data.art b/lib/v2/tencent/templates/coronavirus/data.art new file mode 100644 index 0000000000..a5c80d081c --- /dev/null +++ b/lib/v2/tencent/templates/coronavirus/data.art @@ -0,0 +1,4 @@ +

新增确诊:

+{{@todayConfirm}}


+

现有确诊:

{{@totalNowConfirm}}


+

累计确诊:

{{@totalConfirm}}


+

累计死亡:

{{@totalDead}}