commented unused function
This commit is contained in:
@@ -36,7 +36,7 @@ const USER_AGENT: &str = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/
|
||||
/// - Not an equity (ETF, bond, etc.)
|
||||
/// - Missing critical fields
|
||||
/// - Network or JSON parsing errors
|
||||
pub async fn check_ticker_exists(ticker: &str) -> anyhow::Result<PrimaryInfo> {
|
||||
/*pub async fn check_ticker_exists(ticker: &str) -> anyhow::Result<PrimaryInfo> {
|
||||
let url = format!(
|
||||
"https://query1.finance.yahoo.com/v10/finance/quoteSummary/{}?modules=price%2CassetProfile",
|
||||
ticker
|
||||
@@ -149,7 +149,7 @@ pub async fn check_ticker_exists(ticker: &str) -> anyhow::Result<PrimaryInfo> {
|
||||
exchange_mic,
|
||||
currency,
|
||||
})
|
||||
}
|
||||
}*/
|
||||
|
||||
/// Fetches earnings events for a ticker using a dedicated ScrapeTask.
|
||||
///
|
||||
@@ -546,6 +546,67 @@ pub async fn download_isin_lei_csv() -> anyhow::Result<Option<String>> {
|
||||
let parsed_filename = parse_gleif_filename(&filename);
|
||||
logger::log_info(&format!("Corporate Scraper: Downloaded file: {} -> {}", filename, parsed_filename)).await;
|
||||
|
||||
// Determine date (DDMMYYYY) from parsed filename: "isin-lei-DDMMYYYY.csv"
|
||||
let mut date_str = String::new();
|
||||
if let Some(start_idx) = parsed_filename.find("isin-lei-") {
|
||||
let rest = &parsed_filename[start_idx + 9..];
|
||||
if rest.len() >= 8 {
|
||||
date_str = rest[0..8].to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// If we parsed a date, use/create a date folder under cache/gleif and operate inside it; otherwise use cache root.
|
||||
let date_dir = if !date_str.is_empty() {
|
||||
let p = gleif_cache_dir.join(&date_str);
|
||||
// Ensure the date folder exists (create if necessary)
|
||||
if let Err(e) = std::fs::create_dir_all(&p) {
|
||||
let msg = format!("Failed to create date directory {:?}: {}", p, e);
|
||||
logger::log_warn(&msg).await;
|
||||
None
|
||||
} else {
|
||||
Some(p)
|
||||
}
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Choose the directory where we'll look for existing files and where we'll save the new ones
|
||||
let target_dir = date_dir.clone().unwrap_or_else(|| gleif_cache_dir.to_path_buf());
|
||||
|
||||
// If the date folder exists (or was created), prefer any *_clean.csv inside it and return that immediately
|
||||
if let Some(ref ddir) = date_dir {
|
||||
if let Ok(entries) = std::fs::read_dir(ddir) {
|
||||
for entry in entries.flatten() {
|
||||
if let Some(name) = entry.file_name().to_str() {
|
||||
if name.to_lowercase().ends_with("_clean.csv") {
|
||||
let path = ddir.join(name);
|
||||
logger::log_info(&format!("Found existing clean GLEIF CSV: {}", path.display())).await;
|
||||
return Ok(Some(path.to_string_lossy().to_string()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If no clean file found in the date folder (or date folder doesn't exist), check whether the csv/zip already exist in the target dir
|
||||
let csv_candidate_name = parsed_filename.replace(".zip", ".csv");
|
||||
let csv_candidate = target_dir.join(&csv_candidate_name);
|
||||
let zip_candidate = target_dir.join(&parsed_filename);
|
||||
|
||||
if csv_candidate.exists() {
|
||||
logger::log_info(&format!("Found existing GLEIF CSV: {}", csv_candidate.display())).await;
|
||||
return Ok(Some(csv_candidate.to_string_lossy().to_string()));
|
||||
}
|
||||
if zip_candidate.exists() {
|
||||
// If zip exists but csv does not, extract later; for now prefer returning csv path (may be created by extraction step)
|
||||
let inferred_csv = target_dir.join(csv_candidate_name);
|
||||
if inferred_csv.exists() {
|
||||
logger::log_info(&format!("Found existing extracted CSV next to ZIP: {}", inferred_csv.display())).await;
|
||||
return Ok(Some(inferred_csv.to_string_lossy().to_string()));
|
||||
}
|
||||
// otherwise we'll overwrite/extract into target_dir below
|
||||
}
|
||||
|
||||
let bytes = match resp.bytes().await {
|
||||
Ok(b) => b,
|
||||
Err(e) => {
|
||||
@@ -555,9 +616,13 @@ pub async fn download_isin_lei_csv() -> anyhow::Result<Option<String>> {
|
||||
return Ok(None);
|
||||
}
|
||||
};
|
||||
// Ensure target directory exists (create if it's the date folder and was absent earlier)
|
||||
if let Some(ref ddir) = date_dir {
|
||||
let _ = std::fs::create_dir_all(ddir);
|
||||
}
|
||||
|
||||
let zip_path = gleif_cache_dir.join(&parsed_filename);
|
||||
let csv_path = gleif_cache_dir.join(parsed_filename.replace(".zip", ".csv"));
|
||||
let zip_path = target_dir.join(&parsed_filename);
|
||||
let csv_path = target_dir.join(parsed_filename.replace(".zip", ".csv"));
|
||||
|
||||
if let Err(e) = tokio::fs::write(&zip_path, &bytes).await {
|
||||
let msg = format!("Failed to write ZIP file: {}", e);
|
||||
@@ -616,19 +681,16 @@ pub async fn download_isin_lei_csv() -> anyhow::Result<Option<String>> {
|
||||
if let Err(e) = csv_file.read_to_end(&mut csv_bytes) {
|
||||
let msg = format!("Failed to extract CSV: {}", e);
|
||||
logger::log_error(&msg).await;
|
||||
println!("{}", msg);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
if let Err(e) = tokio::fs::write(&csv_path, &csv_bytes).await {
|
||||
let msg = format!("Failed to save CSV file: {}", e);
|
||||
logger::log_error(&msg).await;
|
||||
println!("{}", msg);
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
let msg = format!("✓ ISIN/LEI CSV extracted: {:?}", csv_path);
|
||||
println!("{}", msg);
|
||||
logger::log_info(&msg).await;
|
||||
|
||||
Ok(Some(csv_path.to_string_lossy().to_string()))
|
||||
|
||||
Reference in New Issue
Block a user