From 928b089cc83873be9221a74427bc60647eb2d34c Mon Sep 17 00:00:00 2001 From: Fatpandac <1779196284@qq.com> Date: Sat, 9 Apr 2022 14:18:49 +0800 Subject: [PATCH] =?UTF-8?q?feat(route):=20add=20=E9=80=9B=E4=B8=A2=20(#950?= =?UTF-8?q?3)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat(route): add 逛丢 * fix(route): fix path --- docs/shopping.md | 18 ++++++++++++++ lib/v2/guangdiu/cheaps.js | 28 ++++++++++++++++++++++ lib/v2/guangdiu/index.js | 44 +++++++++++++++++++++++++++++++++++ lib/v2/guangdiu/maintainer.js | 5 ++++ lib/v2/guangdiu/radar.js | 25 ++++++++++++++++++++ lib/v2/guangdiu/rank.js | 38 ++++++++++++++++++++++++++++++ lib/v2/guangdiu/router.js | 5 ++++ 7 files changed, 163 insertions(+) create mode 100644 lib/v2/guangdiu/cheaps.js create mode 100644 lib/v2/guangdiu/index.js create mode 100644 lib/v2/guangdiu/maintainer.js create mode 100644 lib/v2/guangdiu/radar.js create mode 100644 lib/v2/guangdiu/rank.js create mode 100644 lib/v2/guangdiu/router.js diff --git a/docs/shopping.md b/docs/shopping.md index ec371da3ba..55889d781f 100644 --- a/docs/shopping.md +++ b/docs/shopping.md @@ -143,6 +143,24 @@ For instance, in +## 逛丢 + +### 国内折扣 + + + +### 海外折扣 + + + +### 一小时风云榜 + + + +### 九块九 + + + ## 好好住 ### 整屋案例 diff --git a/lib/v2/guangdiu/cheaps.js b/lib/v2/guangdiu/cheaps.js new file mode 100644 index 0000000000..cea2fa26f2 --- /dev/null +++ b/lib/v2/guangdiu/cheaps.js @@ -0,0 +1,28 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseRelativeDate } = require('@/utils/parse-date'); + +const host = 'https://guangdiu.com'; + +module.exports = async (ctx) => { + const query = ctx.params.query ?? ''; + const url = `${host}/cheaps.php${query ? `?${query}` : ''}`; + + const response = await got(url); + const $ = cheerio.load(response.data); + + const items = $('div.cheapitem.rightborder') + .map((_index, item) => ({ + title: $(item).find('div.cheaptitle').text().trim() + $(item).find('a.cheappriceword').text(), + link: $(item).find('a.cheappriceword').attr('href'), + description: $(item).find('div.cheapimga').html(), + pubDate: parseRelativeDate($(item).find('span.cheapaddtimeword').text()), + })) + .get(); + + ctx.state.data = { + title: `逛丢 - 九块九`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/guangdiu/index.js b/lib/v2/guangdiu/index.js new file mode 100644 index 0000000000..6484eec853 --- /dev/null +++ b/lib/v2/guangdiu/index.js @@ -0,0 +1,44 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseRelativeDate } = require('@/utils/parse-date'); + +const host = 'https://guangdiu.com'; + +module.exports = async (ctx) => { + const query = ctx.params.query ?? ''; + let url; + if (query === 'c=us') { + url = `${host}/?c=us`; + } else { + url = `${host}/${query ? `cate.php?${query}` : ''}`; + } + + const response = await got(url); + const $ = cheerio.load(response.data); + const list = $('#mainleft > div.zkcontent > div.gooditem') + .map((_index, item) => ({ + title: $(item).find('a.goodname').text().trim(), + link: new URL($(item).find('div.iteminfoarea > h2 > a').attr('href'), host).href, + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const $ = cheerio.load(detailResponse.data); + + item.description = $('#dabstract').html() + $('a.dgotobutton').html('前往购买'); + item.pubDate = parseRelativeDate($('span.latesttime').text()); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `逛丢 - ${query.indexOf('c=us') > -1 ? '海外' : '国内'}`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/guangdiu/maintainer.js b/lib/v2/guangdiu/maintainer.js new file mode 100644 index 0000000000..1b8c2f2f23 --- /dev/null +++ b/lib/v2/guangdiu/maintainer.js @@ -0,0 +1,5 @@ +module.exports = { + '/rank': ['fatpandac'], + '/cheaps/:query?': ['fatpandac'], + '/:query?': ['Fatpandac'], +}; diff --git a/lib/v2/guangdiu/radar.js b/lib/v2/guangdiu/radar.js new file mode 100644 index 0000000000..16bbbd17f5 --- /dev/null +++ b/lib/v2/guangdiu/radar.js @@ -0,0 +1,25 @@ +module.exports = { + 'guangdiu.com': { + _name: '逛丢', + '.': [ + { + title: '折扣', + docs: 'https://docs.rsshub.app/other.html#gu-duo-shu-ju', + source: ['/', '/cate.php'], + target: (param, url) => `/guangdiu/${url.indexOf('?') > -1 ? url.split('?')[1] : ''}`, + }, + { + title: '一小时风云榜', + docs: 'https://docs.rsshub.app/other.html#gu-duo-shu-ju', + source: ['/rank'], + target: '/guangdiu/rank', + }, + { + title: '九块九', + docs: 'https://docs.rsshub.app/other.html#gu-duo-shu-ju', + source: ['/cheaps.php'], + target: (param, url) => `/guangdiu/${url.indexOf('?') > -1 ? url.split('?')[1] : ''}`, + }, + ], + }, +}; diff --git a/lib/v2/guangdiu/rank.js b/lib/v2/guangdiu/rank.js new file mode 100644 index 0000000000..e02fde3dd3 --- /dev/null +++ b/lib/v2/guangdiu/rank.js @@ -0,0 +1,38 @@ +const got = require('@/utils/got'); +const cheerio = require('cheerio'); +const { parseRelativeDate } = require('@/utils/parse-date'); + +const host = 'https://guangdiu.com'; + +module.exports = async (ctx) => { + const url = `${host}/rank.php`; + + const response = await got(url); + const $ = cheerio.load(response.data); + const list = $('div.hourrankitem') + .map((_index, item) => ({ + title: $(item).find('a.hourranktitle').text(), + link: new URL($(item).find('a.hourranktitle').attr('href'), host).href, + })) + .get(); + + const items = await Promise.all( + list.map((item) => + ctx.cache.tryGet(item.link, async () => { + const detailResponse = await got(item.link); + const $ = cheerio.load(detailResponse.data); + + item.description = $('#dabstract').html() + $('a.dgotobutton').html('前往购买'); + item.pubDate = parseRelativeDate($('div.hourranktime').text()); + + return item; + }) + ) + ); + + ctx.state.data = { + title: `逛丢 - 一小时风云榜`, + link: url, + item: items, + }; +}; diff --git a/lib/v2/guangdiu/router.js b/lib/v2/guangdiu/router.js new file mode 100644 index 0000000000..85732aa78f --- /dev/null +++ b/lib/v2/guangdiu/router.js @@ -0,0 +1,5 @@ +module.exports = function (router) { + router.get('/rank', require('./rank')); + router.get('/cheaps/:query?', require('./cheaps')); + router.get('/:query?', require('./index')); +};