feat(route): seekingalpha (#10395)

This commit is contained in:
Tony
2022-08-04 22:59:05 +08:00
committed by GitHub
parent 6e3b368de3
commit 06da1b929a
6 changed files with 101 additions and 0 deletions
+14
View File
@@ -28,12 +28,26 @@ pageClass: routes
</RouteEn>
## Seeking Alpha
### Summary
<RouteEn author="TonyRL" example="/seekingalpha/TSM/transcripts" path="/seekingalpha/:symbol/:category?" :paramsDesc="['Stock symbol', 'Category, see below, `news` by default']" radar="1" rssbud="1">
| Analysis | News | Transcripts | Press Releases | Related Analysis |
| ------- | ------- | -------- | ---- | ------ |
| analysis | news | transcripts | press-releases | related-analysis |
</RouteEn>
## TokenInsight
::: tip Tips
TokenInsight also provides official RSS, you can take a look at <https://api.tokeninsight.com/reference/rss>.
:::
### Blogs
<RouteEn author="fuergaosi233" example="/tokeninsight/blog/en" path="/tokeninsight/blog/:lang?" :paramsDesc="['Language, see below, Chinese by default']" />
+12
View File
@@ -56,6 +56,18 @@ pageClass: routes
</Route>
## Seeking Alpha
### Summary
<Route author="TonyRL" example="/seekingalpha/TSM/transcripts" path="/seekingalpha/:symbol/:category?" :paramsDesc="['股票代号', '分类,见下表,默认为 `news`']" radar="1" rssbud="1">
| Analysis | News | Transcripts | Press Releases | Related Analysis |
| -------- | ---- | ----------- | -------------- | ---------------- |
| analysis | news | transcripts | press-releases | related-analysis |
</Route>
## TokenInsight
::: tip 提示
+56
View File
@@ -0,0 +1,56 @@
const got = require('@/utils/got');
const cheerio = require('cheerio');
const { parseDate } = require('@/utils/parse-date');
const dayjs = require('dayjs');
const baseUrl = 'https://seekingalpha.com';
module.exports = async (ctx) => {
const { category = 'news', symbol } = ctx.params;
const pageUrl = `${baseUrl}/symbol/${symbol.toUpperCase()}/${category === 'transcripts' ? `earnings/${category}` : category}`;
const response = await got(`${baseUrl}/api/v3/symbols/${symbol.toUpperCase()}/${category}`, {
searchParams: {
cacheBuster: category === 'news' ? dayjs().format('YYYY-MM-DD') : undefined,
id: symbol.toLowerCase(),
include: 'author,primaryTickers,secondaryTickers,sentiments',
'page[size]': ctx.query.limit ? Number(ctx.query.limit) : category === 'news' ? 40 : 20,
},
});
const list = response.data.data?.map((item) => ({
title: item.attributes.title,
link: new URL(item.links.self, baseUrl).href,
pubDate: parseDate(item.attributes.publishOn),
author: response.data.included.find((i) => i.id === item.relationships.author.data.id).attributes.nick,
}));
const items = list
? await Promise.all(
list.map((item) =>
ctx.cache.tryGet(item.link, async () => {
const response = await got(item.link);
const $ = cheerio.load(response.data);
const summary = $('[data-test-id=article-summary-title]').length ? $('[data-test-id=article-summary-title]').html() + $('[data-test-id=article-summary-title]').next().html() : '';
item.category = $('div[data-test-id=themes-list] a')
.toArray()
.map((c) => $(c).text());
item.description = summary + $('div.paywall-full-content').html();
return item;
})
)
)
: [];
ctx.state.data = {
title: response.data.meta.page.title,
description: response.data.meta.page.description,
link: pageUrl,
image: 'https://seekingalpha.com/samw/static/images/favicon.svg',
item: items,
allowEmpty: true,
language: 'en-US',
};
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = {
'/:symbol/:category?': ['TonyRL'],
};
+13
View File
@@ -0,0 +1,13 @@
module.exports = {
'seekingalpha.com': {
_name: 'Seeking Alpha',
'.': [
{
title: 'Summary',
docs: 'https://docs.rsshub.app/en/finance.html#seeking-alpha',
source: ['/symbol/:symbol/:category', '/symbol/:symbol/earnings/:category'],
target: '/seekingalpha/:symbol/:category',
},
],
},
};
+3
View File
@@ -0,0 +1,3 @@
module.exports = (router) => {
router.get('/:symbol/:category?', require('./index'));
};