Files
WebScraper/src/corporate/update.rs

31 lines
1.1 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 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(())
}