-
Notifications
You must be signed in to change notification settings - Fork 284
Expand file tree
/
Copy pathnews.mjs
More file actions
31 lines (26 loc) · 894 Bytes
/
news.mjs
File metadata and controls
31 lines (26 loc) · 894 Bytes
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
import {getDailyNews, API_KEY} from "./news-util.mjs";
// 主函数
async function main() {
// 检查API密钥
if (API_KEY === 'YOUR_API_KEY') {
console.log('请先获取天行数据API密钥并替换脚本中的YOUR_API_KEY');
console.log('注册地址: https://www.tianapi.com/signup.html');
return;
}
console.log('正在获取国内新闻...');
const news = await getDailyNews();
if (news.length === 0) {
console.log('未获取到新闻数据');
return;
}
// 输出新闻
console.log('\n最新国内新闻:');
news.forEach((item, index) => {
console.log(`\n${index + 1}. ${item.title}`);
console.log(` ${item.description}`);
console.log(` 来源: ${item.source} | 发布时间: ${item.ctime}`);
console.log(` 链接: ${item.url}`);
});
}
// 执行主函数
main();