Skip to content

Commit

Permalink
feat(route): 0818tuan (DIYgod#12035)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyRL authored Mar 3, 2023
1 parent fe9c82a commit 50cc0b8
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docs/shopping.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@ pageClass: routes

# 购物

## 0818 团

### 分类

<Route author="TonyRL" example="/0818tuan" path="/0818tuan/:listId?" :paramsDesc="['活动分类,见下表,默认为 `1`']" radar="1">

| 最新线报 | 实测活动 | 优惠券 |
| ---- | ---- | --- |
| 1 | 2 | 3 |

</Route>

## Alter 中国

### 新闻
Expand Down
47 changes: 47 additions & 0 deletions lib/v2/0818tuan/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
const baseUrl = 'http://www.0818tuan.com';
const { listId = '1' } = ctx.params;
const url = `${baseUrl}/list-${listId}-0.html`;

const { data: response } = await got(url);
const $ = cheerio.load(response);

const list = $(listId === '3' ? '.col-xs-12 .thumbnail > a' : '.col-md-8 .list-group > a')
.toArray()
.map((item) => {
item = $(item);
return {
title: item.attr('title'),
link: `${baseUrl}${item.attr('href')}`,
};
})
.filter((i) => !i.link.includes('m.0818tuan.com/tb1111.php'));

const items = await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const { data: response } = await got(item.link);
const $ = cheerio.load(response);

$('.pageLink, .alert, p[style="margin:15px;"]').remove();

item.description = $('.post-content').html();
item.pubDate = timezone(parseDate($('.panel-body > .text-center').text().replace('时间:', ''), 'YYYY-MM-DD HH:mm:ss'), +8);

return item;
})
)
);

ctx.state.data = {
title: $('head title').text(),
link: url,
image: 'http://www.0818tuan.com/favicon.ico',
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/0818tuan/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/:listId?': ['TonyRL'],
};
13 changes: 13 additions & 0 deletions lib/v2/0818tuan/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'0818tuan.com': {
_name: '0818 团',
'.': [
{
title: '分类',
docs: 'https://docs.rsshub.app/shopping.html#_0818-tuan',
source: ['/:listId', '/'],
target: (params) => `/0818tuan${params.listId ? '/' + params.listId.replace('list-', '').replace('-0.html', '') : ''}`,
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/0818tuan/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:listId?', require('./index'));
};

0 comments on commit 50cc0b8

Please sign in to comment.