A command-line tool to convert handwritten notes to markdown files
feat: added --notion flag to trigger notion page creation upon converting to markdown
Tejas Raskarb725737e6b72
diff --git a/src/cli.rs b/src/cli.rsindex 1311ae9..f1a8984 100644--- a/src/cli.rs+++ b/src/cli.rs@@ -30,9 +30,13 @@ pub enum Commands {#[arg(long, env = "GEMINI_API_KEY", hide_env_values = true)]api_key: Option<String>,- // Prompt the LLM+ /// Prompt the LLM#[arg(short, long, help = "Add a custom prompt to pass to the LLM")]prompt: Option<String>,++ /// Notion Support+ #[arg(short, long, help = "Use Notion to store the generated output")]+ notion: bool,},/// Configure notedmd settings@@ -45,7 +49,7 @@ pub enum Commands {#[arg(long, help = "Set your Claude API key for future use")]set_claude_api_key: Option<String>,- // Set active provider+ /// Set active provider#[arg(long, help = "Set the active provider")]set_provider: Option<String>,@@ -53,11 +57,11 @@ pub enum Commands {#[arg(long, help = "Shows the location of your configuration file")]show_path: bool,- // Show config file+ /// Show config file#[arg(long, help = "Shows the content of your configuration")]show: bool,- // Trigger onboarding flow+ /// Trigger onboarding flow#[arg(long, help = "Edit the configuration file")]edit: bool,},diff --git a/src/clients/notion_client.rs b/src/clients/notion_client.rsindex 573098f..70dd2bd 100644--- a/src/clients/notion_client.rs+++ b/src/clients/notion_client.rs@@ -124,12 +124,17 @@ impl NotionClient {let status = response.status();let response_body = response.text().await?;- if status == StatusCode::OK {+ if status.is_success() {let notion_reponse: NotionResponse = serde_json::from_str(&response_body).map_err(|e| NotedError::ResponseDecodeError(e.to_string()))?;Ok(notion_reponse)} else {- Err(NotedError::ApiError("error".to_string()))+ let error_response: NotionError = serde_json::from_str(&response_body)+ .map_err(|e| NotedError::ResponseDecodeError(e.to_string()))?;+ Err(NotedError::ApiError(format!(+ "Notion API Error ({}): {}",+ status, error_response.message+ )))}}}diff --git a/src/error.rs b/src/error.rsindex 26faf0c..29e551c 100644--- a/src/error.rs+++ b/src/error.rs@@ -41,6 +41,9 @@ pub enum NotedError {#[error(" Claude is not configured properly. Please run 'notedmd config --edit' to set it up.")]ClaudeNotConfigured,+ #[error(" Notion is not configured properly. Please run 'notedmd config --edit' to set it up.")]+ NotionNotConfigured,+#[error(" OpenAI/LM Studio is not configured properly. Please run 'notedmd config --edit' to set it up.")]diff --git a/src/main.rs b/src/main.rsindex 4c7fe3b..6bd8b78 100644--- a/src/main.rs+++ b/src/main.rs@@ -22,6 +22,7 @@ use indicatif::ProgressStyle;use crate::clients::claude_client::ClaudeClient;use crate::clients::gemini_client::GeminiClient;+use crate::clients::notion_client::NotionClient;use crate::clients::ollama_client::OllamaClient;use crate::clients::openai_client::OpenAIClient;use crate::config::NotionConfig;@@ -36,6 +37,7 @@ async fn process_and_save_file(client: &dyn AiProvider,output_dir: Option<&str>,progress_bar: &ProgressBar,+ notion_client: Option<&NotionClient>,) -> Result<(), NotedError> {let path = Path::new(file_path);let file_name = match path.file_name() {@@ -77,13 +79,30 @@ async fn process_and_save_file(None => path.with_extension("md").to_string_lossy().into_owned(),};- match std::fs::write(&output_path, markdown) {+ match std::fs::write(&output_path, &markdown) {Ok(_) => {progress_bar.println(format!("{} {}","✔".green(),format!("Markdown saved to '{}'", output_path.cyan()).green()));+ if let Some(client) = notion_client {+ match client+ .create_notion_page(file_name.to_str().unwrap(), "Testing", &markdown)+ .await+ {+ Ok(page) => {+ progress_bar.println(format!(+ "{} {}",+ "✔".green(),+ format!("Notion page created at '{}'", page.url.cyan()).green()+ ));+ }+ Err(e) => {+ return Err(e);+ }+ }+ };Ok(())}Err(e) => {@@ -356,6 +375,7 @@ async fn run() -> Result<(), NotedError> {output,api_key,prompt,+ notion,} => {let config = Config::load()?;let client: Box<dyn AiProvider> = match config.active_provider.as_deref() {@@ -427,6 +447,18 @@ async fn run() -> Result<(), NotedError> {format!("Input path not found: {}", path),)));}+ let notion_client = if notion {+ if let Some(notion_config) = &config.notion {+ Some(NotionClient::new(+ notion_config.api_key.clone(),+ notion_config.database_id.clone(),+ ))+ } else {+ return Err(NotedError::NotionNotConfigured);+ }+ } else {+ None+ };if input_path.is_dir() {let files_to_convert: Vec<_> = std::fs::read_dir(input_path)?@@ -464,6 +496,7 @@ async fn run() -> Result<(), NotedError> {client.as_ref(),output.as_deref(),&progress_bar,+ notion_client.as_ref(),).await{@@ -492,6 +525,7 @@ async fn run() -> Result<(), NotedError> {client.as_ref(),output.as_deref(),&progress_bar,+ notion_client.as_ref(),).await{