forked from DIYgod/RSSHub
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(route): cfachina (DIYgod#13949)
- Loading branch information
Showing
5 changed files
with
92 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
'/servicesupport/analygarden/:program?': ['TonyRL'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?', | ||
}, | ||
], | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = (router) => { | ||
router.get('/servicesupport/analygarden/:program?', require('./analygarden')); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters