rsshub
Version:
Make RSS Great Again!
177 lines (174 loc) • 5.25 kB
JavaScript
import { n as init_esm_shims, t as __dirname } from "./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 { t as cache_default } from "./cache-Bo__VnGm.mjs";
import "./helpers-DxBp0Pty.mjs";
import { t as art } from "./render-BQo6B4tL.mjs";
import { t as got_default } from "./got-KxxWdaxq.mjs";
import path from "node:path";
import { load } from "cheerio";
//#region lib/routes/eastmoney/utils.ts
init_esm_shims();
function getRatingChangeStr(ratingChange) {
let ratingChangeName = "";
switch (String(ratingChange)) {
case "0":
ratingChangeName = "调高";
break;
case "1":
ratingChangeName = "调低";
break;
case "2":
ratingChangeName = "首次";
break;
case "3":
ratingChangeName = "维持";
break;
case "4":
ratingChangeName = "无";
break;
default:
ratingChangeName = "-";
break;
}
return ratingChangeName;
}
function getEpsOrPeStr(epsOrPe, keepDecimal) {
let EpsOrPeStr = "";
if (epsOrPe !== void 0) EpsOrPeStr = epsOrPe === "" ? "" : Number(epsOrPe).toFixed(keepDecimal);
return EpsOrPeStr;
}
//#endregion
//#region lib/routes/eastmoney/report/index.ts
const route = {
path: "/report/:category",
categories: ["finance"],
view: ViewType.Articles,
example: "/eastmoney/report/strategyreport",
parameters: { category: {
description: "研报类型",
options: [
{
value: "strategyreport",
label: "策略报告"
},
{
value: "macresearch",
label: "宏观研究"
},
{
value: "brokerreport",
label: "券商晨报"
},
{
value: "industry",
label: "行业研报"
},
{
value: "stock",
label: "个股研报"
}
]
} },
features: {
requireConfig: false,
requirePuppeteer: false,
antiCrawler: false,
supportBT: false,
supportPodcast: false,
supportScihub: false
},
radar: [{ source: ["data.eastmoney.com/report/:category"] }],
name: "研究报告",
maintainers: ["syzq"],
handler,
description: `| 策略报告 | 宏观研究 | 券商晨报 | 行业研究 | 个股研报 |
| -------------- | ----------- | ------------ | -------- | -------- |
| strategyreport | macresearch | brokerreport | industry | stock |`
};
async function handler(ctx) {
const baseUrl = "https://data.eastmoney.com";
const { category = "strategyreport" } = ctx.req.param();
const reportType = {
brokerreport: "券商晨报",
industry: "行业研报",
macresearch: "宏观研究",
strategyreport: "策略报告",
stock: "个股研报"
};
const linkType = {
brokerreport: "zw_brokerreport",
industry: "zw_industry",
macresearch: "zw_macresearch",
strategyreport: "zw_strategy",
stock: "info"
};
const $ = load((await got_default(`${baseUrl}/report/${category}`)).data);
const list = JSON.parse($("script").text().match(/var initdata(.=?)(.*?);/)[2]).data.map((item) => {
const stockName = category === "stock" ? `[${item.stockName}]` : "";
return {
title: `[${item.orgSName}]${stockName}${item.title}`,
link: `${baseUrl}/report/${linkType[category]}` + (category === "stock" ? `/${item.infoCode}.html` : `.jshtml?encodeUrl=${item.encodeUrl}`),
pubDate: parseDate(item.publishDate),
author: item.researcher,
originItem: item
};
});
const items = await Promise.all(list.map((item) => {
const tempOriginItem = item.originItem;
delete item.originItem;
return cache_default.tryGet(item.link, async () => {
try {
const { data: response } = await got_default(item.link);
const $$1 = load(response);
if (category === "stock") {
const { title, stockName, stockCode, emRatingName, ratingChange, orgSName, indvInduName } = tempOriginItem;
const ratingChangeStr = getRatingChangeStr(ratingChange);
const currentYear = (/* @__PURE__ */ new Date()).getFullYear();
const nextYear = currentYear + 1;
const description = $$1(".newsContent").html();
const enclosureUrl = $$1("#ContentBody .rightlab").attr("href");
const predictThisYearEps = getEpsOrPeStr(tempOriginItem.predictThisYearEps, 3);
const predictThisYearPe = getEpsOrPeStr(tempOriginItem.predictThisYearPe, 2);
const predictNextYearEps = getEpsOrPeStr(tempOriginItem.predictNextYearEps, 3);
const predictNextYearPe = getEpsOrPeStr(tempOriginItem.predictNextYearPe, 2);
item.enclosure_url = enclosureUrl;
item.description = art(path.join(__dirname, "templates/stock_description-13fa7813.art"), {
title,
stockName,
stockCode,
emRatingName,
ratingChangeStr,
description,
orgSName,
predictThisYearEps,
predictThisYearPe,
predictNextYearEps,
predictNextYearPe,
indvInduName,
currentYear,
nextYear,
enclosureUrl
});
} else {
item.link = $$1(".pdf-link").attr("href");
item.description = $$1(".ctx-content").text();
}
return item;
} catch {
return item;
}
});
}));
return {
title: `东方财富网-${reportType[category]}`,
link: baseUrl,
item: items
};
}
//#endregion
export { route };