Files
RSSHub/lib/routes/finviz/quote.ts
T
Tony a5e2e295dc refactor: fix all get to toArray (#19000)
* refactor: fix all get

* fix(utils/common-config): charset case compare

* Revert "fix(utils/common-config): charset case compare"

This reverts commit 3c1880f2fad53ad2cafddcee7741390fd46fa3d2.

* fix: nga

* fix: notateslaapp

* fix: ps

* fix: xjtu

* fix: enforce error on restricted syntax for get calls

* fix: eslint

* fix: more eslint
2025-05-04 05:24:53 +08:00

58 lines
1.6 KiB
TypeScript

import { Route } from '@/types';
import got from '@/utils/got';
import { load } from 'cheerio';
import { parseDate } from '@/utils/parse-date';
export const route: Route = {
path: '/news/:ticker',
categories: ['finance'],
example: '/finviz/news/AAPL',
parameters: { ticker: 'The stock ticker' },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false,
},
name: 'US Stock News',
maintainers: ['HenryQW'],
handler,
};
async function handler(ctx) {
const link = `https://finviz.com/quote.ashx?t=${ctx.req.param('ticker')}`;
const response = await got(link);
const $ = load(response.body);
const data = $('table.fullview-news-outer tr');
let dateRow = '';
const item = await Promise.all(
data.toArray().map((e) => {
let date = $(e).find('td').first().text().trim();
if (date.includes('-')) {
dateRow = date.split(' ')[0];
} else {
date = `${dateRow} ${date}`;
}
return {
title: $(e).find('a').text(),
pubDate: parseDate(date, 'MMM-DD-YY HH:mmA'),
author: $(e).find('span').text(),
link: $(e).find('a').attr('href'),
};
})
);
const name = $('.fullview-title b').text();
return {
title: `${ctx.req.param('ticker')} ${name} News by Finviz`,
link,
description: `A collection of ${name} news aggregated by Finviz.`,
item,
};
}