31 lines
1.1 KiB
Rust
31 lines
1.1 KiB
Rust
// src/corporate/update.rs
|
||
use super::{scraper::*, storage::*, types::*};
|
||
use crate::config::Config;
|
||
|
||
use chrono::Local;
|
||
use std::collections::{HashMap, HashSet};
|
||
|
||
|
||
pub async fn run_full_update(client: &fantoccini::Client, tickers: Vec<String>, config: &Config) -> anyhow::Result<()> {
|
||
println!("Updating {} tickers (prices from {})", tickers.len(), config.corporate_start_date);
|
||
|
||
let today = chrono::Local::now().format("%Y-%m-%d").to_string();
|
||
|
||
for ticker in tickers {
|
||
print!(" → {:6} ", ticker);
|
||
|
||
// Earnings
|
||
if let Ok(events) = fetch_earnings_history(client, &ticker).await {
|
||
merge_and_save_events(&ticker, events.clone()).await?;
|
||
println!("{} earnings", events.len());
|
||
}
|
||
|
||
// Prices – now using config.corporate_start_date
|
||
if let Ok(prices) = fetch_price_history(client, &ticker, &config.corporate_start_date, &today).await {
|
||
save_prices_for_ticker(&ticker, prices).await?;
|
||
}
|
||
|
||
tokio::time::sleep(tokio::time::Duration::from_millis(250)).await;
|
||
}
|
||
Ok(())
|
||
} |