35 lines
964 B
Rust
35 lines
964 B
Rust
use clap::Parser;
|
|
use readwise_bulk_upload::config::Config;
|
|
use readwise_bulk_upload::readwise::DocumentPayload;
|
|
use readwise_bulk_upload::sql::TaskManager;
|
|
use readwise_bulk_upload::{Error, Result};
|
|
use std::fs::File;
|
|
use tracing_subscriber;
|
|
use figment::{Figment, providers::{Serialized, Env}};
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
let args: Config = Figment::new()
|
|
.merge(Serialized::defaults(Config::parse()))
|
|
.merge(Env::prefixed("APP_"))
|
|
.extract()?;
|
|
|
|
tracing_subscriber::fmt()
|
|
.with_max_level(args.log_level())
|
|
.init();
|
|
|
|
let file = File::open(args.path()).map_err(|_| {
|
|
Error::Runtime(format!(
|
|
r#"The file "{}" could not be open"#,
|
|
args.path().display()
|
|
))
|
|
})?;
|
|
|
|
let documents: Vec<DocumentPayload> = serde_json::from_reader(file)?;
|
|
|
|
let task_manager = TaskManager::new().await?;
|
|
|
|
task_manager.load_tasks(documents).await?;
|
|
|
|
Ok(())
|
|
}
|