-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathkzz.mjs
More file actions
56 lines (51 loc) · 1.64 KB
/
kzz.mjs
File metadata and controls
56 lines (51 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import {getNowKzz} from "./kzz-util.mjs";
/**
* 主函数 - 测试用
*/
async function main() {
try {
// 支持正负偏移量测试
const testCases = [
{offset: 0, desc: "今天"},
{offset: 1, desc: "明天"},
{offset: -1, desc: "昨天"},
{offset: 7, desc: "7天后"},
{offset: -7, desc: "7天前"}
];
for (const testCase of testCases) {
console.log(`\n===== 测试 ${testCase.desc} (偏移量: ${testCase.offset}) =====`);
const kzzData = await getNowKzz(
`test_${testCase.offset}`,
'http://data.eastmoney.com/kzz/',
testCase.offset
);
if (kzzData.length > 0) {
console.log(`找到 ${kzzData.length} 个可转债:`);
kzzData.forEach((item, index) => {
console.log(`${index + 1}. ${item.name} (${item.code}) - ${item.date}`);
});
} else {
console.log(`未找到 ${testCase.desc} 的可转债数据`);
}
}
console.log('\n所有测试完成');
} catch (error) {
console.error('测试失败:', error.message);
}
}
// 使用立即执行的异步函数调用main
(async () => {
try {
// await main();
const kzzData = await getNowKzz(
`test_7`,
'http://data.eastmoney.com/kzz/',
7
);
console.log(kzzData);
console.log('程序执行完成');
} catch (error) {
console.error('程序执行失败:', error.message);
process.exit(1);
}
})();