From 84ded422f1e17732879f9ab230ba61173bf95f39 Mon Sep 17 00:00:00 2001 From: a14907 <1490747123@qq.com> Date: Fri, 27 Sep 2019 10:28:52 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AE=9E=E7=8E=B0=E5=A4=A9=E6=B6=AF?= =?UTF-8?q?=E8=AE=BA=E5=9D=9B=E7=9A=84=E6=8A=93=E5=8F=96=20(#3143)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/bbs.md | 14 ++++++++++++++ lib/router.js | 5 +++++ lib/routes/tianya/comments.js | 36 +++++++++++++++++++++++++++++++++++ lib/routes/tianya/index.js | 34 +++++++++++++++++++++++++++++++++ lib/routes/tianya/user.js | 36 +++++++++++++++++++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 lib/routes/tianya/comments.js create mode 100644 lib/routes/tianya/index.js create mode 100644 lib/routes/tianya/user.js diff --git a/docs/bbs.md b/docs/bbs.md index 78ad80248a..411d44f10d 100644 --- a/docs/bbs.md +++ b/docs/bbs.md @@ -160,3 +160,17 @@ pageClass: routes ### 回帖 + +## 天涯论坛 + +### 子版块 + + + +### 用户帖子 + + + +### 用户的回帖 + + diff --git a/lib/router.js b/lib/router.js index febf926a79..aa0a86faec 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1649,6 +1649,11 @@ router.get('/soul/:id', require('./routes/soul')); // 单向空间 router.get('/owspace/read/:type?', require('./routes/owspace/read')); +// 天涯论坛 +router.get('/tianya/index/:type', require('./routes/tianya/index')); +router.get('/tianya/user/:userid', require('./routes/tianya/user')); +router.get('/tianya/comments/:userid', require('./routes/tianya/comments')); + // eleme router.get('/eleme/open/announce', require('./routes/eleme/open/announce')); router.get('/eleme/open-be/announce', require('./routes/eleme/open-be/announce')); diff --git a/lib/routes/tianya/comments.js b/lib/routes/tianya/comments.js new file mode 100644 index 0000000000..2f7e5c6a3b --- /dev/null +++ b/lib/routes/tianya/comments.js @@ -0,0 +1,36 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { userid } = ctx.params; + const url = 'http://www.tianya.cn/' + userid + '/bbs?t=post'; + const responseraw = await got(url, { headers: { Referer: 'http://bbs.tianya.cn' } }); + const $ = cheerio.load(responseraw.data); + const username = $('div.portrait h2 a') + .first() + .text(); + + const turl = `http://www.tianya.cn/api/bbsuser?method=userinfo.ice.getUserTotalReplyList¶ms.userId=${userid}¶ms.pageSize=20¶ms.bMore=true`; + const response = await got(turl, { headers: { Referer: 'http://bbs.tianya.cn' } }); + const json = response.data; + const items = json.data.rows.map((ele) => { + const title = ele.title; + const clicknum = ` 点击数:${ele.click_counter},回复数:${ele.reply_counter}`; + const link = `http://bbs.tianya.cn/go_reply_position.jsp?item=${ele.item}&id=${ele.art_id}&rid=${ele.reply_id}`; + const date = ele.reply_time; + + const pubDate = new Date(date).toUTCString(); + return { + title, + description: title + clicknum, + link, + pubDate, + }; + }); + ctx.state.data = { + title: username + '的天涯回帖', + description: username, + link: url, + item: items, + }; +}; diff --git a/lib/routes/tianya/index.js b/lib/routes/tianya/index.js new file mode 100644 index 0000000000..37dd33ac6f --- /dev/null +++ b/lib/routes/tianya/index.js @@ -0,0 +1,34 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { type } = ctx.params; + const url = 'http://bbs.tianya.cn/list-' + type + '-1.shtml'; + const response = await got(url, { headers: { Referer: 'http://bbs.tianya.cn' } }); + const $ = cheerio.load(response.data); + const typeTitle = $('div.location div.text strong').text(); + const items = $('table > tbody ~ tbody > tr') + .map((_, ele) => { + const $item = cheerio.load(ele); + const title = $item('td.td-title a').text(); + const link = $item('td.td-title a').attr('href'); + const date = $item('td') + .last() + .attr('title'); + + const pubDate = new Date(date).toUTCString(); + return { + title, + description: title, + link, + pubDate, + }; + }) + .get(); + ctx.state.data = { + title: typeTitle, + description: typeTitle, + link: url, + item: items, + }; +}; diff --git a/lib/routes/tianya/user.js b/lib/routes/tianya/user.js new file mode 100644 index 0000000000..a27070ac03 --- /dev/null +++ b/lib/routes/tianya/user.js @@ -0,0 +1,36 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +module.exports = async (ctx) => { + const { userid } = ctx.params; + const url = 'http://www.tianya.cn/' + userid + '/bbs?t=post'; + const responseraw = await got(url, { headers: { Referer: 'http://bbs.tianya.cn' } }); + const $ = cheerio.load(responseraw.data); + const username = $('div.portrait h2 a') + .first() + .text(); + + const turl = `http://www.tianya.cn/api/bbsuser?method=userinfo.ice.getUserTotalArticleList¶ms.userId=${userid}¶ms.pageSize=20¶ms.bMore=true`; + const response = await got(turl, { headers: { Referer: 'http://bbs.tianya.cn' } }); + const json = response.data; + const items = json.data.rows.map((ele) => { + const title = ele.title; + const clicknum = ` 点击数:${ele.click_counter},回复数:${ele.reply_counter}`; + const link = `http://bbs.tianya.cn/post-${ele.item}-${ele.art_id}-1.shtml`; + const date = ele.compose_time; + + const pubDate = new Date(date).toUTCString(); + return { + title, + description: title + clicknum, + link, + pubDate, + }; + }); + ctx.state.data = { + title: username + '的天涯帖子', + description: username, + link: url, + item: items, + }; +};