UNPKG

rsshub

Version:
88 lines (86 loc) 3.49 kB
import "./esm-shims-CzJ_djXG.mjs"; import { t as config } from "./config-C37vj7VH.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 got_default } from "./got-KxxWdaxq.mjs"; import crypto from "node:crypto"; import { load } from "cheerio"; import https from "node:https"; //#region lib/routes/cib/whpj.ts const route = { path: "/whpj/:format?", categories: ["other"], example: "/cib/whpj/xh?filter_title=USD", parameters: { format: "输出的标题格式,默认为标题 + 所有价格。短格式仅包含货币名称。" }, features: { requireConfig: false, requirePuppeteer: false, antiCrawler: false, supportBT: false, supportPodcast: false, supportScihub: false }, radar: [{ source: ["cib.com.cn/"], target: "/whpj" }], name: "外汇牌价", maintainers: ["Qixingchen"], handler, url: "cib.com.cn/", description: `| 短格式 | 现汇买卖 | 现钞买卖 | 现汇买入 | 现汇卖出 | 现钞买入 | 现钞卖出 | | ------ | -------- | -------- | -------- | -------- | -------- | -------- | | short | xh | xc | xhmr | xhmc | xcmr | xcmc |` }; async function handler(ctx) { const agent = new https.Agent({ secureOptions: crypto.constants.SSL_OP_LEGACY_SERVER_CONNECT }); const response = await got_default("https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do", { agent: { https: agent } }); const cookies = response.headers["set-cookie"].map((item) => item.split(";")[0]).join(";"); let date = load(response.data)("div.main-body").find("div.labe_text").text(); date = date.split("\n ")[1].replace("日期:", "").trim(); date = date.slice(0, 11) + date.slice(15); const link = "https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery/list?_search=false&dataSet.rows=80&dataSet.page=1&dataSet.sidx=&dataSet.sord=asc"; const data = await cache_default.tryGet(link, async () => { return (await got_default(link, { headers: { Cookie: cookies }, agent: { https: agent } })).data; }, config.cache.contentExpire, false); const format = ctx.req.param("format"); return { title: "中国兴业银行外汇牌价", link: "https://personalbank.cib.com.cn/pers/main/pubinfo/ifxQuotationQuery.do", item: data.rows.map((item) => { const name = `${item.cell[0]} ${item.cell[1]}`; const xhmr = `现汇买入价:${item.cell[3]}`; const xcmr = `现钞买入价:${item.cell[5]}`; const xhmc = `现汇卖出价:${item.cell[4]}`; const xcmc = `现钞卖出价:${item.cell[6]}`; const content = `${xhmr} ${xcmr} ${xhmc} ${xcmc}`; return { title: formatTitle(name, xhmr, xcmr, xhmc, xcmc, content, format), pubDate: parseDate(date, "YYYY年MM月DD日 HH:mm:ss"), description: content.replaceAll(/\s/g, "<br>"), guid: `${item.cell[0]} ${item.cell[1]} ${date}` }; }) }; } function formatTitle(name, xhmr, xcmr, xhmc, xcmc, content, format) { switch (format) { case "short": return name; case "xh": return `${name} ${xhmr} ${xhmc}`; case "xc": return `${name} ${xcmr} ${xcmc}`; case "xhmr": return `${name} ${xhmr}`; case "xhmc": return `${name} ${xhmc}`; case "xcmr": return `${name} ${xcmr}`; case "xcmc": return `${name} ${xcmc}`; default: return `${name} ${content}`; } } //#endregion export { route };