From 06da1b929ae8a95a7479228fda8230f2a46de68b Mon Sep 17 00:00:00 2001 From: Tony Date: Thu, 4 Aug 2022 02:59:05 -1200 Subject: [PATCH] feat(route): seekingalpha (#10395) --- docs/en/finance.md | 14 ++++++++ docs/finance.md | 12 +++++++ lib/v2/seekingalpha/index.js | 56 +++++++++++++++++++++++++++++++ lib/v2/seekingalpha/maintainer.js | 3 ++ lib/v2/seekingalpha/radar.js | 13 +++++++ lib/v2/seekingalpha/router.js | 3 ++ 6 files changed, 101 insertions(+) create mode 100644 lib/v2/seekingalpha/index.js create mode 100644 lib/v2/seekingalpha/maintainer.js create mode 100644 lib/v2/seekingalpha/radar.js create mode 100644 lib/v2/seekingalpha/router.js diff --git a/docs/en/finance.md b/docs/en/finance.md index 076cf9154..682ade23e 100644 --- a/docs/en/finance.md +++ b/docs/en/finance.md @@ -28,12 +28,26 @@ pageClass: routes +## Seeking Alpha + +### Summary + + + +| Analysis | News | Transcripts | Press Releases | Related Analysis | +| ------- | ------- | -------- | ---- | ------ | +| analysis | news | transcripts | press-releases | related-analysis | + + + ## TokenInsight + ::: tip Tips TokenInsight also provides official RSS, you can take a look at . ::: + ### Blogs diff --git a/docs/finance.md b/docs/finance.md index fdc21db29..6d2b1a79a 100644 --- a/docs/finance.md +++ b/docs/finance.md @@ -56,6 +56,18 @@ pageClass: routes +## Seeking Alpha + +### Summary + + + +| Analysis | News | Transcripts | Press Releases | Related Analysis | +| -------- | ---- | ----------- | -------------- | ---------------- | +| analysis | news | transcripts | press-releases | related-analysis | + + + ## TokenInsight ::: tip 提示 diff --git a/lib/v2/seekingalpha/index.js b/lib/v2/seekingalpha/index.js new file mode 100644 index 000000000..b7aea4dd8 --- /dev/null +++ b/lib/v2/seekingalpha/index.js @@ -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', + }; +}; diff --git a/lib/v2/seekingalpha/maintainer.js b/lib/v2/seekingalpha/maintainer.js new file mode 100644 index 000000000..4648b0d81 --- /dev/null +++ b/lib/v2/seekingalpha/maintainer.js @@ -0,0 +1,3 @@ +module.exports = { + '/:symbol/:category?': ['TonyRL'], +}; diff --git a/lib/v2/seekingalpha/radar.js b/lib/v2/seekingalpha/radar.js new file mode 100644 index 000000000..f0e0420db --- /dev/null +++ b/lib/v2/seekingalpha/radar.js @@ -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', + }, + ], + }, +}; diff --git a/lib/v2/seekingalpha/router.js b/lib/v2/seekingalpha/router.js new file mode 100644 index 000000000..7ff84268a --- /dev/null +++ b/lib/v2/seekingalpha/router.js @@ -0,0 +1,3 @@ +module.exports = (router) => { + router.get('/:symbol/:category?', require('./index')); +};