From fbabb3679c734fa4f100fc426252684cf454dba1 Mon Sep 17 00:00:00 2001 From: Luyu Huang Date: Sat, 1 Feb 2020 18:11:02 +0800 Subject: [PATCH] feat: add route for netease god (#3801) --- assets/radar-rules.js | 11 ++++++++++ docs/game.md | 6 ++++++ lib/router.js | 3 +++ lib/routes/netease/ds.js | 46 ++++++++++++++++++++++++++++++++++++++++ lib/utils/date.js | 11 ++++++---- 5 files changed, 73 insertions(+), 4 deletions(-) create mode 100644 lib/routes/netease/ds.js diff --git a/assets/radar-rules.js b/assets/radar-rules.js index aa844a4f3e..9cad69fcf9 100644 --- a/assets/radar-rules.js +++ b/assets/radar-rules.js @@ -978,6 +978,17 @@ }, ], }, + '163.com': { + _name: '网易', + ds: [ + { + title: '网易大神', + docs: 'https://docs.rsshub.app/game.html#wang-yi-da-shen', + source: '/user/:id', + target: '/netease/ds/:id', + }, + ], + }, 'suzhou.gov.cn': { _name: '苏州市政府', www: [ diff --git a/docs/game.md b/docs/game.md index 56ec3f1b24..42d4874598 100644 --- a/docs/game.md +++ b/docs/game.md @@ -277,6 +277,12 @@ Example: `https://store.steampowered.com/search/?specials=1&term=atelier` 中的 +## 网易大神 + +### 用户发帖 + + + ## 王者荣耀 ### 新闻中心 diff --git a/lib/router.js b/lib/router.js index aa77861d44..d9931441b4 100644 --- a/lib/router.js +++ b/lib/router.js @@ -2178,4 +2178,7 @@ router.get('/mqube/top', require('./routes/mqube/top')); // Letterboxd router.get('/letterboxd/user/diary/:username', require('./routes/letterboxd/userdiary')); +// 网易大神 +router.get('/netease/ds/:id', require('./routes/netease/ds')); + module.exports = router; diff --git a/lib/routes/netease/ds.js b/lib/routes/netease/ds.js new file mode 100644 index 0000000000..f9be3f6c68 --- /dev/null +++ b/lib/routes/netease/ds.js @@ -0,0 +1,46 @@ +const url = require('url'); +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const date = require('@/utils/date'); + +const root_url = 'https://ds.163.com/'; + +module.exports = async (ctx) => { + const id = ctx.params.id; + if (!id) { + throw Error('Bad parameter. See https://docs.rsshub.app/game.html#wang-yi-da-shen'); + } + + const current_url = url.resolve(root_url, '/user/' + id); + const response = await got({ + method: 'get', + url: current_url, + }); + + const $ = cheerio.load(response.data); + const list = $('main.user-page__main div.feed-card') + .map((_, item) => { + item = $(item); + const a = item.find('a.feed-card__link-hide'); + const desc = item.find('div.feed-card__body'); + const title = desc.find('div.feed-text').text(); + return { + title: title, + link: a.attr('href'), + description: desc.html(), + pubDate: date( + item + .find('time.userbar__time') + .text() + .trim() + ), + }; + }) + .get(); + + ctx.state.data = { + title: $('title').text(), + link: current_url, + item: list, + }; +}; diff --git a/lib/utils/date.js b/lib/utils/date.js index a2754de920..6bed865db8 100644 --- a/lib/utils/date.js +++ b/lib/utils/date.js @@ -20,11 +20,11 @@ module.exports = (html, timeZone = -serverOffset) => { } else if (/(\d+)年前/.exec(html)) { math = /(\d+)年前/.exec(html); date.setFullYear(date.getFullYear() - math[1]); - } else if (/今天 (\d+):(\d+)/.exec(html)) { - math = /今天 (\d+):(\d+)/.exec(html); + } else if (/今天\s*(\d+):(\d+)/.exec(html)) { + math = /今天\s*(\d+):(\d+)/.exec(html); date = new Date(date.getFullYear(), date.getMonth(), date.getDate(), math[1], math[2]); - } else if (/昨天 (\d+):(\d+)/.exec(html)) { - math = /昨天 (\d+):(\d+)/.exec(html); + } else if (/昨天\s*(\d+):(\d+)/.exec(html)) { + math = /昨天\s*(\d+):(\d+)/.exec(html); date = new Date(date.getFullYear(), date.getMonth(), date.getDate() - 1, math[1], math[2]); } else if (/前天\s*(\d+):(\d+)/.exec(html)) { math = /前天\s*(\d+):(\d+)/.exec(html); @@ -56,6 +56,9 @@ module.exports = (html, timeZone = -serverOffset) => { } else if (/(\d+)月(\d+)日/.exec(html)) { math = /(\d+)月(\d+)日/.exec(html); date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2]); + } else if (/(\d+)\/(\d+)/.exec(html)) { + math = /(\d+)\/(\d+)/.exec(html); + date = new Date(date.getFullYear(), parseInt(math[1]) - 1, math[2]); } else if (/(\d+)-(\d+)-(\d+)/.exec(html)) { math = /(\d+)-(\d+)-(\d+)/.exec(html); date = new Date(math[1], parseInt(math[2]) - 1, math[3]);