diff --git a/src/maple/gtfs_handlers/fix_files.rs b/src/maple/gtfs_handlers/fix_files.rs new file mode 100644 index 0000000..92b7c6f --- /dev/null +++ b/src/maple/gtfs_handlers/fix_files.rs @@ -0,0 +1,24 @@ +use std::fs::File; +use std::io::Read; +use std::io::Write; + +pub fn fix_files_in_gtfs_directory(path: &str) -> Result<(), anyhow::Error> { + //read stop file + let stops = format!("{}/stops.txt", path); + + let mut f = File::open(&stops)?; + + let mut buffer: Vec = Vec::new(); + + let read = f.read_to_end(&mut buffer)?; + + let stops_string = String::from_utf8_lossy(&buffer); + + //write stops string back + + let mut f = File::create(&stops)?; + + f.write_all(stops_string.as_bytes())?; + + Ok(()) +} diff --git a/src/maple/gtfs_handlers/mod.rs b/src/maple/gtfs_handlers/mod.rs index d80797c..5a7fc64 100644 --- a/src/maple/gtfs_handlers/mod.rs +++ b/src/maple/gtfs_handlers/mod.rs @@ -1,5 +1,6 @@ pub mod colour_correction; pub mod convex_hull; +pub mod fix_files; pub mod flatten; pub mod hull_from_gtfs; pub mod rename_route_labels; diff --git a/src/maple/main.rs b/src/maple/main.rs index c4c2c9a..d90bfbd 100644 --- a/src/maple/main.rs +++ b/src/maple/main.rs @@ -343,6 +343,14 @@ async fn run_ingest() -> Result<(), Box> { rc_feed, ); + let fix_stops_file = gtfs_handlers::fix_files::fix_files_in_gtfs_directory( + format!( + "{}/{}", + gtfs_uncompressed_temp_storage, to_ingest_feed.feed_id + ) + .as_str(), + ); + (to_ingest_feed.feed_id.clone(), flatten_feed_result.is_ok()) } }))