don't really need this anymore, but since its in git now i can always get it back if i need something
This commit is contained in:
@@ -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",
|
||||
] }
|
@@ -1,28 +0,0 @@
|
||||
use std::sync::{
|
||||
atomic::{AtomicU8, Ordering},
|
||||
Arc,
|
||||
};
|
||||
|
||||
pub struct CtrlC {
|
||||
counter: Arc<AtomicU8>,
|
||||
}
|
||||
|
||||
impl CtrlC {
|
||||
pub fn new() -> Self {
|
||||
let counter: Arc<AtomicU8> = 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)
|
||||
}
|
||||
}
|
@@ -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<i32>,
|
||||
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::<Airport>().flatten().collect::<Vec<_>>();
|
||||
|
||||
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(())
|
||||
}
|
Reference in New Issue
Block a user