对比图完成
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
|
||||
import { spawn } from 'child_process';
|
||||
|
||||
async function runScraper(scraperPath, startDate, endDate) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const args = [scraperPath];
|
||||
if (startDate) {
|
||||
args.push('--start', startDate);
|
||||
}
|
||||
if (endDate) {
|
||||
args.push('--end', endDate);
|
||||
}
|
||||
|
||||
const proc = spawn('bun', args, { stdio: 'inherit' });
|
||||
proc.on('close', (code) => {
|
||||
if (code === 0) {
|
||||
resolve();
|
||||
} else {
|
||||
reject(new Error(`Process exited with code ${code}`));
|
||||
}
|
||||
});
|
||||
proc.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function fetchOneYearData() {
|
||||
console.log('='.repeat(70));
|
||||
console.log('📊 获取近一年数据');
|
||||
console.log('='.repeat(70));
|
||||
|
||||
const currentDate = new Date();
|
||||
const startDate = new Date(currentDate);
|
||||
startDate.setFullYear(startDate.getFullYear() - 1);
|
||||
|
||||
const startDateStr = startDate.toISOString().split('T')[0];
|
||||
const endDateStr = currentDate.toISOString().split('T')[0];
|
||||
|
||||
console.log(`时间范围: ${startDateStr} 至 ${endDateStr}`);
|
||||
console.log('');
|
||||
|
||||
console.log('='.repeat(70));
|
||||
console.log('💱 开始获取 USD-CNY 汇率数据...');
|
||||
console.log('='.repeat(70));
|
||||
|
||||
let usdSuccess = false;
|
||||
try {
|
||||
await runScraper('./scraper/usd-cny-rate.scraper.js', startDateStr, endDateStr);
|
||||
console.log(`✅ USD-CNY 汇率数据更新完成`);
|
||||
usdSuccess = true;
|
||||
} catch (error) {
|
||||
console.error(`❌ USD-CNY 汇率数据更新失败:`, error.message);
|
||||
}
|
||||
|
||||
console.log('');
|
||||
console.log('='.repeat(70));
|
||||
console.log('📈 开始获取沪深300指数数据...');
|
||||
console.log('='.repeat(70));
|
||||
|
||||
let sh300Success = false;
|
||||
try {
|
||||
await runScraper('./scraper/sh300.scraper.js', startDateStr, endDateStr);
|
||||
console.log(`✅ 沪深300指数数据更新完成`);
|
||||
sh300Success = true;
|
||||
} catch (error) {
|
||||
console.error(`❌ 沪深300指数数据更新失败:`, error.message);
|
||||
}
|
||||
|
||||
console.log('');
|
||||
console.log('='.repeat(70));
|
||||
console.log('📊 数据获取完成');
|
||||
console.log('='.repeat(70));
|
||||
console.log(`USD-CNY 汇率: ${usdSuccess ? '✅ 成功' : '❌ 失败'}`);
|
||||
console.log(`沪深300指数: ${sh300Success ? '✅ 成功' : '❌ 失败'}`);
|
||||
console.log('='.repeat(70));
|
||||
}
|
||||
|
||||
fetchOneYearData();
|
||||
Reference in New Issue
Block a user