Skip to content

Commit

Permalink
Count unzips correctly, flatten septa code
Browse files Browse the repository at this point in the history
  • Loading branch information
kylerchin committed Mar 21, 2024
1 parent 8e16878 commit 50ce2e6
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name = "catenary-backend"
version = "0.1.0"
edition = "2021"

[build]
rustflags = ["-Z", "threads=8"]

[lints.rust]
unused_must_use = "deny"
non_ascii_idents = "deny"
Expand Down
26 changes: 25 additions & 1 deletion src/maple/gtfs_handlers/flatten.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ use std::io::Cursor;
use std::io::Read;
use std::path::PathBuf;

// Extracts a sub zip file and uses it as the parent folder
pub fn extract_sub_zip(feed_id: &str, sub_folder: &str) -> Result<(), Box<dyn Error>> {
let source_path = format!("gtfs_uncompressed/{}/{}.zip", feed_id, sub_folder);
let target_path = format!("gtfs_uncompressed/{}", feed_id);

// Attempt to open file and pass back error if failed
let mut file = File::open(source_path)?;
let mut buf: Vec<u8> = vec![];

// read bytes and pass back error if unable to read
let read = file.read_to_end(&mut buf)?;
let target_dir = PathBuf::from(target_path);

zip_extract::extract(Cursor::new(buf), &target_dir, true)?;

Ok(())
}

pub fn flatten_feed(feed_id: &str) -> Result<(), Box<dyn Error>> {
let _ = fs::create_dir("gtfs_uncompressed");

Expand All @@ -23,7 +41,13 @@ pub fn flatten_feed(feed_id: &str) -> Result<(), Box<dyn Error>> {
zip_extract::extract(Cursor::new(buf), &target_dir, true)?;

// go into folder and unnest folders
if feed_id == "f-dr4-septa~rail" || feed_id == "f-dr4-septa~bus" {}
if feed_id == "f-dr4-septa~rail" {
extract_sub_zip("f-dr4-septa~rail", "google_rail")?;
}

if feed_id == "f-dr4-septa~bus" {
extract_sub_zip("f-dr4-septa~bus", "google_bus")?;
}

Ok(())
}
2 changes: 1 addition & 1 deletion src/maple/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ async fn run_ingest() -> Result<(), Box<dyn Error>> {
.await;

let successful_unzip_feeds_count =
unzip_feeds.iter().map(|x| x.1).collect::<Vec<bool>>().len();
unzip_feeds.iter().map(|x| x.1 == true).collect::<Vec<bool>>().len();

println!(
"{} of {} unzipped",
Expand Down

0 comments on commit 50ce2e6

Please sign in to comment.