added gettin opnv setup files

This commit is contained in:
2025-12-09 19:23:54 +01:00
parent f95e9e2427
commit c2408d9a56
13 changed files with 478 additions and 53 deletions

View File

@@ -1,20 +1,21 @@
// src/main.rs
mod economic;
mod corporate;
mod config;
mod webdriver;
mod corporate;
mod economic;
mod util;
mod scraper;
use anyhow::Result;
use config::Config;
use webdriver::webdriver::ChromeDriverPool;
use scraper::webdriver::ChromeDriverPool;
use util::directories::DataPaths;
use util::logger;
use util::{logger, opnv};
use std::sync::Arc;
/// The entry point of the application.
///
/// This function loads the configuration, initializes a shared ChromeDriver pool,
/// fetches the latest VPNBook OpenVPN configurations if VPN rotation is enabled,
/// and sequentially runs the full updates for corporate and economic data.
/// Sequential execution helps prevent resource exhaustion from concurrent
/// chromedriver instances and avoids spamming the target websites with too many requests.
@@ -22,8 +23,8 @@ use std::sync::Arc;
/// # Errors
///
/// Returns an error if configuration loading fails, pool initialization fails,
/// or if either update function encounters an issue (e.g., network errors,
/// scraping failures, or chromedriver spawn failures like "program not found").
/// VPN fetching fails (if enabled), or if either update function encounters an issue
/// (e.g., network errors, scraping failures, or chromedriver spawn failures like "program not found").
#[tokio::main]
async fn main() -> Result<()> {
let config = Config::load().map_err(|err| {
@@ -40,16 +41,29 @@ async fn main() -> Result<()> {
})?;
logger::log_info("=== Application started ===").await;
logger::log_info(&format!("Config: economic_start_date={}, corporate_start_date={}, lookahead_months={}, max_parallel_tasks={}",
config.economic_start_date, config.corporate_start_date, config.economic_lookahead_months, config.max_parallel_tasks)).await;
logger::log_info(&format!("Config: economic_start_date={}, corporate_start_date={}, lookahead_months={}, max_parallel_instances={}, enable_vpn_rotation={}",
config.economic_start_date, config.corporate_start_date, config.economic_lookahead_months, config.max_parallel_instances, config.enable_vpn_rotation)).await;
// Initialize the shared ChromeDriver pool once
let pool_size = config.max_parallel_tasks;
let pool_size = config.max_parallel_instances;
logger::log_info(&format!("Initializing ChromeDriver pool with size: {}", pool_size)).await;
let pool = Arc::new(ChromeDriverPool::new(pool_size).await?);
logger::log_info("✓ ChromeDriver pool initialized successfully").await;
// Fetch VPNBook configs if VPN rotation is enabled
if config.enable_vpn_rotation {
logger::log_info("--- Fetching latest VPNBook OpenVPN configurations ---").await;
let (username, password, files) =
util::opnv::fetch_vpnbook_configs(&pool, paths.cache_dir()).await?;
logger::log_info(&format!("Fetched VPN username: {}, password: {}", username, password)).await;
for file in &files {
logger::log_info(&format!("Extracted OVPN: {:?}", file)).await;
}
// Optionally, store username/password for rotation use (e.g., in a file or global state)
// For now, just log them; extend as needed for rotation integration
}
// Run economic update first, passing the shared pool
logger::log_info("--- Starting economic data update ---").await;
economic::run_full_update(&config, &pool).await?;