rsshub
Version:
Make RSS Great Again!
84 lines (82 loc) • 2.86 kB
JavaScript
import "./esm-shims-CzJ_djXG.mjs";
import "./config-C37vj7VH.mjs";
import { t as ViewType } from "./types-D84BRIt4.mjs";
import "./dist-BInvbO1W.mjs";
import "./logger-Czu8UMNd.mjs";
import "./ofetch-BIyrKU3Y.mjs";
import { t as parseDate } from "./parse-date-BrP7mxXf.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import { t as timezone } from "./timezone-D8cuwzTY.mjs";
import { t as invalid_parameter_default } from "./invalid-parameter-rr4AgGpp.mjs";
import { load } from "cheerio";
//#region lib/routes/finviz/news.ts
const categories = {
news: 0,
blogs: 1
};
const route = {
path: "/:category?",
categories: ["finance"],
view: ViewType.Articles,
example: "/finviz",
parameters: { category: {
description: "Category, see below, News by default",
options: Object.keys(categories).map((key) => ({
value: key,
label: key
}))
} },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["finviz.com/news.ashx", "finviz.com/"] }],
name: "News",
maintainers: ["nczitzk"],
handler,
url: "finviz.com/news.ashx",
description: `| News | Blogs |
| ---- | ---- |
| news | blogs |`
};
async function handler(ctx) {
const { category = "News" } = ctx.req.param();
const limit = ctx.req.query("limit") ? Number.parseInt(ctx.req.query("limit"), 10) : 200;
if (!Object.hasOwn(categories, category.toLowerCase())) throw new invalid_parameter_default(`No category '${category}'.`);
const rootUrl = "https://finviz.com";
const currentUrl = new URL("news.ashx", rootUrl).href;
const { data: response } = await got_default(currentUrl);
const $ = load(response);
const items = $("table.table-fixed").eq(categories[category.toLowerCase()]).find("tr").slice(0, limit).toArray().map((item) => {
item = $(item);
const a = item.find("a.nn-tab-link");
const descriptionMatches = a.parent().prop("data-boxover")?.match(/<td class='news_tooltip-tab'>(.*?)<\/td>/);
const authorMatches = item.find("use").first().prop("href")?.match(/#(.*?)-(light|dark)/);
return {
title: a.text(),
link: a.prop("href"),
description: descriptionMatches ? descriptionMatches[1] : void 0,
author: authorMatches ? authorMatches[1].replaceAll("-", " ") : "finviz",
pubDate: timezone(parseDate(item.find("td.news_date-cell").text(), ["HH:mmA", "MMM-DD"]), -4)
};
}).filter((item) => item.title);
const icon = $("link[rel=\"icon\"]").prop("href");
return {
item: items,
title: `finviz - ${category}`,
link: currentUrl,
description: $("meta[name=\"description\"]").prop("content"),
language: "en-US",
image: new URL($("a.logo svg use").first().prop("href"), rootUrl).href,
icon,
logo: icon,
subtitle: $("title").text()
};
}
//#endregion
export { route };