Skip to content

Commit

Permalink
fix(route): mpaypass news (DIYgod#9367)
Browse files Browse the repository at this point in the history
* fix(route): mpaypass news

* refactor: migrate to v2

* fix: parseDate
  • Loading branch information
genghis-yang authored and RikkaBlue committed Apr 9, 2022
1 parent e008efd commit a03175d
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 75 deletions.
4 changes: 2 additions & 2 deletions docs/new-media.md
Original file line number Diff line number Diff line change
Expand Up @@ -3714,12 +3714,12 @@ column 为 third 时可选的 category:

### 新闻

<Route author="LogicJake" example="/mpaypass/news" path="/mpaypass/news"/>
<Route author="LogicJake genghis-yang" example="/mpaypass/news" path="/mpaypass/news"/>

### 分类

<Route author="zhuan-zhu" example="/mpaypass/main/policy" path="mpaypass/main/:type?"
:paramsDesc="['新闻类型,类型可在URL中找到,类似policy,eye等,空或其他任意值展示最新新闻']"/>
:paramsDesc="['新闻类型类型可在URL中找到,类似`policy``eye`,空或其他任意值展示最新新闻']"/>

## 亿欧网

Expand Down
6 changes: 3 additions & 3 deletions lib/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -1265,9 +1265,9 @@ router.get('/xiaoheihe/discount/:platform?', lazyloadRouteHandler('./routes/xiao
// 惠誉评级
router.get('/fitchratings/site/:type', lazyloadRouteHandler('./routes/fitchratings/site'));

// 移动支付
router.get('/mpaypass/news', lazyloadRouteHandler('./routes/mpaypass/news'));
router.get('/mpaypass/main/:type?', lazyloadRouteHandler('./routes/mpaypass/main'));
// 移动支付 migrated to v2
// router.get('/mpaypass/news', lazyloadRouteHandler('./routes/mpaypass/news'));
// router.get('/mpaypass/main/:type?', lazyloadRouteHandler('./routes/mpaypass/main'));

// 新浪科技探索
router.get('/sina/discovery/:type', lazyloadRouteHandler('./routes/sina/discovery'));
Expand Down
43 changes: 0 additions & 43 deletions lib/routes/mpaypass/news.js

This file was deleted.

50 changes: 23 additions & 27 deletions lib/routes/mpaypass/main.js → lib/v2/mpaypass/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const got = require('../../utils/got');
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const timezone = require('@/utils/timezone');

module.exports = async (ctx) => {
let title_url = '';
Expand Down Expand Up @@ -29,40 +31,34 @@ module.exports = async (ctx) => {
.map(function () {
const info = {
title: $(this).find('#title').text(),
link: $(this).find('#pic a').attr('href'),
pic: $(this).find('#pic img').attr('src'),
link: $(this).find('#title').find('a').attr('href'),
time: $(this).find('#time').text(),
category: $(this)
.find('#keywords')
.find('a')
.toArray()
.map((e) => $(e).text().trim()),
};
return info;
})
.get();

const out = await Promise.all(
list.map(async (info) => {
const title = info.title;
let date = info.time.toString();
date = date.substring(2, date.length);
const link = info.link;
list.map((info) =>
ctx.cache.tryGet(info.link, async () => {
const response = await got(info.link);
const $ = cheerio.load(response.data);
const newsbody = $('div.newsbody').html();

const cache = await ctx.cache.get(link);
if (cache) {
return Promise.resolve(JSON.parse(cache));
}

const response = await got.get(link);
const $ = cheerio.load(response.data);
const newsbody = $('div.newsbody').html();

const single = {
title,
link,
pubDate: date,
description: newsbody,
};

ctx.cache.set(link, JSON.stringify(single));
return Promise.resolve(single);
})
return {
title: info.title,
link: info.link,
pubDate: timezone(parseDate(info.time), +8),
description: newsbody,
category: info.category,
};
})
)
);

ctx.state.data = {
Expand Down
4 changes: 4 additions & 0 deletions lib/v2/mpaypass/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
'/main/:type?': ['zhuan-zhu'],
'/news': ['LogicJake', 'genghis-yang'],
};
39 changes: 39 additions & 0 deletions lib/v2/mpaypass/news.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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 link = 'http://m.mpaypass.com.cn';
const listData = await got(link);
const $list = cheerio.load(listData.data);
ctx.state.data = {
title: '新闻 - 移动支付网',
link,
language: 'zh-CN',
item: await Promise.all(
$list('.Newslist-li')
.map((_, el) => {
const $el = $list(el);
const $a = $el.find('.Newslist-title a');
const href = $a.attr('href');
const title = $a.text();
const date = $el.find('.Newslist-time span').text();

return ctx.cache.tryGet(href, async () => {
const contentData = await got.get(href);
const $content = cheerio.load(contentData.data);
const description = $content('.newslist-body').html();

return {
title,
description,
link: href,
pubDate: timezone(parseDate(date), +8),
};
});
})
.get()
),
};
};
19 changes: 19 additions & 0 deletions lib/v2/mpaypass/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = {
'mpaypass.com.cn': {
_name: '移动支付网',
'.': [
{
title: '新闻',
docs: 'https://docs.rsshub.app/new-media.html#yi-dong-zhi-fu-wang',
source: '/',
target: '/mpaypass/news',
},
{
title: '分类',
docs: 'https://docs.rsshub.app/new-media.html#yi-dong-zhi-fu-wang',
source: ['/:type', '/'],
target: (params) => `/mpaypass/main/${params.type.replace('.html', '')}`,
},
],
},
};
4 changes: 4 additions & 0 deletions lib/v2/mpaypass/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = (router) => {
router.get('/main/:type?', require('./main'));
router.get('/news', require('./news'));
};

0 comments on commit a03175d

Please sign in to comment.