just add data loader here
Some checks failed
Create and publish a Docker image / build-and-push-image (push) Has been cancelled

This commit is contained in:
Nicholas Orlowsky 2025-09-12 19:34:35 -04:00
parent 04ae29eb27
commit 55df6bdb16
No known key found for this signature in database
GPG key ID: A9F3BA4C0AA7A70B
23 changed files with 4097 additions and 1 deletions

74
data_loader/src/main.rs Normal file
View file

@ -0,0 +1,74 @@
use dotenv::dotenv;
use libseptastic::stop::Stop;
use septa::route_stop;
use septa_json::direction::Direction;
use septa_json::route::Route;
use septa_json::route_stop::RouteStop;
use septa_json::schedule_day::{Calendar, ScheduleDay};
use septa_json::stop_schedule::StopSchedule;
use sqlx::postgres::PgPoolOptions;
use std::collections::{HashMap, HashSet};
use std::sync::{Arc, Mutex};
use std::{fs, thread};
use std::path::Path;
use std::time::SystemTime;
use env_logger::{Builder, Env};
use log::{error, info, warn};
pub mod traits;
use traits::*;
pub mod septa_json;
pub mod septa;
pub mod fetchers;
#[tokio::main]
async fn main() -> ::anyhow::Result<()> {
dotenv().ok();
let env = Env::new().filter_or("RUST_LOG", "data_loader=info");
Builder::from_env(env).init();
let database_url = std::env::var("DATABASE_URL").expect("Database URL");
let pool = PgPoolOptions::new()
.max_connections(5)
.connect(&database_url)
.await?;
let septa_data = fetchers::septa::SeptaFetcher::fetch_septa_data().await?;
let mut tx = pool.begin().await?;
libseptastic::route::Route::create_table(&mut tx).await?;
libseptastic::direction::Direction::create_table(&mut tx).await?;
libseptastic::stop::Stop::create_table(&mut tx).await?;
libseptastic::route_stop::RouteStop::create_table(&mut tx).await?;
libseptastic::stop_schedule::StopSchedule::create_table(&mut tx).await?;
libseptastic::schedule_day::ScheduleDay::create_table(&mut tx).await?;
info!("Inserting Route Data");
libseptastic::route::Route::insert_many(septa_data.routes, &mut tx).await?;
info!("Inserting Direction Data");
libseptastic::direction::Direction::insert_many(septa_data.directions, &mut tx).await?;
info!("Inserting Stop Data");
libseptastic::stop::Stop::insert_many(septa_data.stops, &mut tx).await?;
info!("Inserting Route-Stop Data");
libseptastic::route_stop::RouteStop::insert_many(septa_data.route_stops, &mut tx).await?;
info!("Inserting Stop Schedule Data");
libseptastic::stop_schedule::StopSchedule::insert_many(septa_data.stop_schedules, &mut tx).await?;
info!("Inserting Schedule Day Data");
libseptastic::schedule_day::ScheduleDay::insert_many(septa_data.schedule_days, &mut tx).await?;
tx.commit().await?;
pool.close().await;
Ok(())
}