Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from diygod:master #2281

Merged
merged 4 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions lib/v2/cfachina/analygarden.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 { program = '分析师园地' } = ctx.params;
const baseUrl = 'https://www.cfachina.org';
let pageData,
pageUrl = `${baseUrl}/servicesupport/analygarden/`;

if (program !== '分析师园地') {
pageUrl = `${pageUrl}${program}/`;

const response = await got(pageUrl);
const $ = cheerio.load(response.data);
program = $('script:contains("Paging")')
.text()
.match(/var name = '(.+)';/)[1];
pageData = {
category: $('.crumb a')
.toArray()
.map((item) => $(item).text())
.slice(-2),
};
}

const { data: response } = await got(`${baseUrl}/qx-search/api/wcmSearch/getDataByProgram`, {
headers: {
accept: 'application/json, text/plain, */*',
},
searchParams: {
pageNo: 1,
pageSize: ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20,
keyword: '',
startTime: '',
endTime: '',
type: '',
programName: program,
},
});

const items = response.data.dataList.map((item) => {
const link = new URL(item.docPubUrl, baseUrl).href;
return {
title: item.docTitle,
author: item.docAuthor,
link,
pubDate: timezone(parseDate(item.operTime), +8),
enclosure_url: link,
enclosure_type: `application/${link.split('.').pop()}`,
};
});

ctx.state.data = {
title: `${pageData?.category.toReversed().join(' - ') ?? '分析师园地'} - 中国期货业协会`,
link: pageUrl,
item: items,
};
};
3 changes: 3 additions & 0 deletions lib/v2/cfachina/maintainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
'/servicesupport/analygarden/:program?': ['TonyRL'],
};
13 changes: 13 additions & 0 deletions lib/v2/cfachina/radar.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = {
'cfachina.org': {
_name: '中国期货业协会',
'.': [
{
title: '分析师园地',
docs: 'https://docs.rsshub.app/other#zhong-guo-qi-huo-ye-xie-hui',
source: ['/servicesupport/analygarden/:program?', '/'],
target: '/cfachina/servicesupport/analygarden/:program?',
},
],
},
};
3 changes: 3 additions & 0 deletions lib/v2/cfachina/router.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/servicesupport/analygarden/:program?', require('./analygarden'));
};
33 changes: 0 additions & 33 deletions lib/v2/huxiu/article.js

This file was deleted.

36 changes: 0 additions & 36 deletions lib/v2/huxiu/author.js

This file was deleted.

38 changes: 13 additions & 25 deletions lib/v2/huxiu/briefColumn.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
const got = require('@/utils/got');
const { parseDate } = require('@/utils/parse-date');
const { baseUrl, briefApi, ProcessFeed } = require('./utils');

const { apiBriefRootUrl, processItems, fetchBriefColumnData } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const link = `${briefApi}/briefColumn/getContentListByCategoryId`;
const { data: response } = await got
.post(link, {
form: {
platform: 'www',
brief_column_id: id,
},
})
.json();
const {
data: { data: briefDetail },
} = await got.post(`${briefApi}/briefColumn/detail`, {
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;

const apiUrl = new URL('briefColumn/getContentListByCategoryId', apiBriefRootUrl).href;

const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
brief_column_id: id,
pagesize: limit,
},
});

const list = response.datalist.map((item) => ({
title: item.title,
link: `${baseUrl}/brief/${item.brief_id}`,
description: item.preface,
pubDate: parseDate(item.publish_time, 'X'),
}));
ctx.state.json = response.data.datalist;

const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet);

const items = await ProcessFeed(list, ctx.cache);
const data = await fetchBriefColumnData(id);

ctx.state.data = {
title: `虎嗅 - ${briefDetail.name}`,
description: briefDetail.summary,
image: briefDetail.head_img,
link: `${baseUrl}/briefColumn/${id}.html`,
item: items,
...data,
};
};
28 changes: 28 additions & 0 deletions lib/v2/huxiu/channel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const got = require('@/utils/got');

const { rootUrl, apiArticleRootUrl, processItems, fetchData } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;

const apiUrl = new URL(`web/${id ? 'channel' : 'article'}/articleList`, apiArticleRootUrl).href;
const currentUrl = new URL(id ? `channel/${id}.html` : 'article', rootUrl).href;

const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
channel_id: id,
pagesize: limit,
},
});

const items = await processItems(response.data?.dataList ?? response.data.datalist, limit, ctx.cache.tryGet);

const data = await fetchData(currentUrl);

ctx.state.data = {
item: items,
...data,
};
};
30 changes: 30 additions & 0 deletions lib/v2/huxiu/club.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const got = require('@/utils/got');

const { apiBriefRootUrl, processItems, fetchClubData } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 20;

const apiUrl = new URL('club/briefList', apiBriefRootUrl).href;

const { data, briefColumnId } = await fetchClubData(id);

const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
club_id: id,
brief_column_id: briefColumnId,
pagesize: limit,
},
});

ctx.state.json = response.data.datalist;

const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet);

ctx.state.data = {
item: items,
...data,
};
};
40 changes: 14 additions & 26 deletions lib/v2/huxiu/collection.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,27 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const utils = require('./utils');
const { parseDate } = require('@/utils/parse-date');

const { rootUrl, apiArticleRootUrl, processItems, fetchData } = require('./util');

module.exports = async (ctx) => {
const { id } = ctx.params;
const link = `${utils.baseUrl}/collection/${id}.html`;
const { data: response } = await got(link, {
https: {
rejectUnauthorized: false,
},
});
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;

const $ = cheerio.load(response);
const apiUrl = new URL('web/collection/articleList', apiArticleRootUrl).href;
const currentUrl = new URL(`collection/${id}.html`, rootUrl).href;

const initialState = utils.parseInitialState($);

const { collectionDetail } = initialState.collectionDetail;
const list = collectionDetail.article_list.datalist.map((e) => ({
title: e.title,
link: `${utils.baseUrl}/article/${e.aid}.html`,
description: e.summary,
pubDate: parseDate(e.dateline, 'X'),
author: e.user_info.username,
}));
const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
collection_id: id,
},
});

const items = await utils.ProcessFeed(list, ctx.cache);
const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet);

const info = `虎嗅 - ${collectionDetail.name}`;
const data = await fetchData(currentUrl);

ctx.state.data = {
title: info,
description: collectionDetail.summary,
image: collectionDetail.icon,
link,
item: items,
...data,
};
};
13 changes: 8 additions & 5 deletions lib/v2/huxiu/maintainer.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
module.exports = {
'/article': ['HenryQW'],
'/author/:id': ['HenryQW'],
'/collection/:id': ['AlexdanerZe'],
'/article': ['HenryQW', 'nczitzk'],
'/briefcolumn/:id': ['Fatpandac', 'nczitzk'],
'/channel/:id?': ['nczitzk'],
'/club/:id': ['nczitzk'],
'/collection/:id': ['AlexdanerZe', 'nczitzk'],
'/member/:id/:type?': ['HenryQW', 'nczitzk'],
'/moment': ['nczitzk'],
'/tag/:id': ['xyqfer', 'HenryQW'],
'/search/:keyword': ['xyqfer', 'HenryQW'],
'/search/:keyword': ['xyqfer', 'HenryQW', 'nczitzk'],
'/tag/:id': ['xyqfer', 'HenryQW', 'nczitzk'],
};
27 changes: 27 additions & 0 deletions lib/v2/huxiu/member.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const got = require('@/utils/got');

const { rootUrl, apiMemberRootUrl, processItems, fetchData } = require('./util');

module.exports = async (ctx) => {
const { id, type = 'article' } = ctx.params;
const limit = ctx.query.limit ? parseInt(ctx.query.limit, 10) : 10;

const apiUrl = new URL(`web/${type}/${type}List`, apiMemberRootUrl).href;
const currentUrl = new URL(`member/${id}${type === 'article' ? '' : `/${type}`}.html`, rootUrl).href;

const { data: response } = await got.post(apiUrl, {
form: {
platform: 'www',
uid: id,
},
});

const items = await processItems(response.data.datalist, limit, ctx.cache.tryGet);

const data = await fetchData(currentUrl);

ctx.state.data = {
item: items,
...data,
};
};
Loading
Loading