From c47e52688729538eaceb246cf4c543b34df3714c Mon Sep 17 00:00:00 2001 From: Luyu Huang Date: Sun, 8 Mar 2020 01:36:23 +0800 Subject: [PATCH] feat: add route for hpoi user activity (#4190) --- docs/anime.md | 10 +++++++++ lib/router.js | 1 + lib/routes/hpoi/user.js | 45 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 lib/routes/hpoi/user.js diff --git a/docs/anime.md b/docs/anime.md index 16599a0cd1..6a78e104e9 100644 --- a/docs/anime.md +++ b/docs/anime.md @@ -139,6 +139,16 @@ pageClass: routes +### 用户动态 + + + +| 想买的手办 | 预定的手办 | 已入的手办 | +| ---------- | ---------- | ---------- | +| want | preorder | buy | + + + ## say 花火 ### 文章 diff --git a/lib/router.js b/lib/router.js index 19367e0e22..501b7d5f6a 100644 --- a/lib/router.js +++ b/lib/router.js @@ -1507,6 +1507,7 @@ router.get('/guanchazhe/index/:type', require('./routes/guanchazhe/index')); // Hpoi 手办维基 router.get('/hpoi/info/:type?', require('./routes/hpoi/info')); router.get('/hpoi/:category/:words', require('./routes/hpoi')); +router.get('/hpoi/user/:user_id/:caty', require('./routes/hpoi/user')); // 通用CurseForge router.get('/curseforge/:gameid/:catagoryid/:projectid/files', require('./routes/curseforge/generalfiles')); diff --git a/lib/routes/hpoi/user.js b/lib/routes/hpoi/user.js new file mode 100644 index 0000000000..197bcc94bd --- /dev/null +++ b/lib/routes/hpoi/user.js @@ -0,0 +1,45 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); + +const root_url = 'https://www.hpoi.net'; +const caties = { + want: '想买的手办', + preorder: '预定的手办', + buy: '已入的手办', +}; + +module.exports = async (ctx) => { + const { user_id, caty } = ctx.params; + let title = caties[caty]; + if (!title) { + throw Error('Bad category. See https://docs.rsshub.app/anime.html#hpoi-shou-ban-wei-ji'); + } + + const url = `${root_url}/user/${user_id}/hobby?order=actionDate&favState=${caty}&view=5&category=100&sortType=1`; + const response = await got({ + method: 'get', + url: url, + }); + + const $ = cheerio.load(response.data); + const list = $('#content > div.action-box div.action-detail') + .map((_, item) => { + item = $(item); + const img = item.find('div.list-5-left > a > img').attr('src'); + const a = item.find('div.list-5-right > a.action-title'); + return { + title: a.text(), + link: a.attr('href'), + description: `

${a.text()}

`, + }; + }) + .get(); + + title = $('div.col-md-15.col-sm-15 > div:nth-child(2)').text() + title; + + ctx.state.data = { + title: title, + link: url, + item: list, + }; +};