From 6e4a52c9c2f072d7f3d7f5bc5420170ea0cd38af Mon Sep 17 00:00:00 2001 From: Avii Date: Thu, 31 Oct 2024 00:19:39 +0100 Subject: [PATCH] don't really need this anymore, but since its in git now i can always get it back if i need something --- parser/Cargo.toml | 13 ---- parser/src/ctrl_c.rs | 28 -------- parser/src/main.rs | 153 ------------------------------------------- 3 files changed, 194 deletions(-) delete mode 100644 parser/Cargo.toml delete mode 100644 parser/src/ctrl_c.rs delete mode 100644 parser/src/main.rs diff --git a/parser/Cargo.toml b/parser/Cargo.toml deleted file mode 100644 index d51cd8a..0000000 --- a/parser/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "parser" -version = "0.1.0" -edition = "2021" - -[dependencies] -anyhow = "1.0.91" -csv = "1.3.0" -ctrlc = "3.4.5" -serde = { version = "1.0.213", features = ["derive"] } -simconnect-sdk = { path = "D:/source/MSFS/simconnect-sdk-rs/simconnect-sdk", features = [ - "derive", -] } diff --git a/parser/src/ctrl_c.rs b/parser/src/ctrl_c.rs deleted file mode 100644 index 96fe6a9..0000000 --- a/parser/src/ctrl_c.rs +++ /dev/null @@ -1,28 +0,0 @@ -use std::sync::{ - atomic::{AtomicU8, Ordering}, - Arc, -}; - -pub struct CtrlC { - counter: Arc, -} - -impl CtrlC { - pub fn new() -> Self { - let counter: Arc = Default::default(); - let c = counter.clone(); - ctrlc::set_handler(move || { - c.fetch_add(1, Ordering::SeqCst); - if c.load(Ordering::SeqCst) >= 3 { - std::process::exit(1); - } - }) - .unwrap(); - - Self { counter } - } - - pub fn count(&self) -> u8 { - self.counter.load(Ordering::SeqCst) - } -} diff --git a/parser/src/main.rs b/parser/src/main.rs deleted file mode 100644 index 2c772ce..0000000 --- a/parser/src/main.rs +++ /dev/null @@ -1,153 +0,0 @@ -mod ctrl_c; - -use ctrl_c::CtrlC; -use std::{fs, io::Write, thread::sleep, time::Duration}; - -use serde::Deserialize; -use simconnect_sdk::{Notification, SimConnect, SystemEventRequest}; - -#[derive(Clone, Debug, Deserialize)] -struct Airport { - id: usize, - ident: String, - #[serde(rename = "type")] - airport_type: String, - name: String, - latitude_deg: f64, - longitude_deg: f64, - elevation_ft: Option, - continent: String, - iso_country: String, - iso_region: String, - municipality: String, - scheduled_service: String, - gps_code: String, - iata_code: String, - local_code: String, - home_link: String, - wikipedia_link: String, - keywords: String, -} - -// cross reference ICAOs with data from the sim - -fn main() -> Result<(), anyhow::Error> { - let Ok(mut simconnect) = SimConnect::new("Airport Crawler") else { - panic!("Game not running, gotta wait for it here"); - }; - - let mut csv = csv::ReaderBuilder::new() - .has_headers(true) - .delimiter(b',') - .trim(csv::Trim::All) - .from_path("./airports.csv")?; - - let airports = csv.deserialize::().flatten().collect::>(); - - let mut list = vec![]; - - let ctrl_c = CtrlC::new(); - - loop { - if ctrl_c.count() > 0 { - break; - } - - if let Ok(Some(event)) = simconnect.get_next_dispatch() { - match event { - Notification::Open => { - // simconnect.subscribe_to_system_event(SystemEventRequest::FlightLoaded)?; - simconnect.request_facilities_list(simconnect_sdk::FacilityType::Airport)?; - } - Notification::AirportList(vec) => { - for a in &vec { - let Some(ap) = airports - .iter() - .find(|e| e.ident.to_lowercase() == a.ident.to_lowercase()) - else { - let Some(ap) = airports - .iter() - .find(|e| e.local_code.to_lowercase() == a.ident.to_lowercase()) - else { - // eprintln!("{} not found in as ident nor local_code", a.ident.to_lowercase()); - list.push(Airport { - id: 0, - ident: a.ident.clone(), - airport_type: "N/A".to_string(), - name: "N/A".to_string(), - latitude_deg: a.lat, - longitude_deg: a.lon, - elevation_ft: Some(a.alt.round() as i32), - continent: "N/A".to_string(), - iso_country: "N/A".to_string(), - iso_region: "N/A".to_string(), - municipality: "N/A".to_string(), - scheduled_service: "N/A".to_string(), - gps_code: "N/A".to_string(), - iata_code: "N/A".to_string(), - local_code: "N/A".to_string(), - home_link: "N/A".to_string(), - wikipedia_link: "N/A".to_string(), - keywords: "N/A".to_string(), - }); - - continue; - }; - let mut ap = ap.to_owned(); - ap.ident = ap.local_code.clone(); - - list.push(ap); - continue; - }; - list.push(ap.to_owned()); - } - - dbg!(&vec.len()); - } - Notification::Quit => break, - _ => todo!(), - } - } - sleep(Duration::from_millis(16)); - } - - let mut writer = fs::File::create("./airports.sql")?; - let mut string_builder = String::new(); - let mut i = 0; - string_builder += "INSERT INTO airports ( ident, airport_type, name, latitude_deg, longitude_deg, elevation_ft, iso_country, iso_region, municipality, scheduled_service, gps_code, iata_code, local_code, keywords ) VALUES\n"; - - for airport in list { - string_builder += &format!( - "\t('{}', '{}', '{}', {}, {}, {}, '{}', '{}', '{}', '{}', '{}', '{}', '{}', '{}')", - airport.ident.replace('\'', "''"), - airport.airport_type.replace('\'', "''"), - airport.name.replace('\'', "''"), - airport.latitude_deg, - airport.longitude_deg, - airport.elevation_ft.unwrap_or(0), - airport.iso_country.replace('\'', "''"), - airport.iso_region.replace('\'', "''"), - airport.municipality.replace('\'', "''"), - airport.scheduled_service.replace('\'', "''"), - airport.gps_code.replace('\'', "''"), - airport.iata_code.replace('\'', "''"), - airport.local_code.replace('\'', "''"), - airport.keywords.replace('\'', "''"), - ); - - if i == 50 { - i = 0; - string_builder += ";\n\nINSERT INTO airports ( ident, airport_type, name, latitude_deg, longitude_deg, elevation_ft, iso_country, iso_region, municipality, scheduled_service, gps_code, iata_code, local_code, keywords ) VALUES\n"; - - continue; - } else { - string_builder += ",\n"; - } - - i += 1; - } - - writer.write_all(string_builder.as_bytes())?; - - Ok(()) -}