67 lines
1.5 KiB
Rust
67 lines
1.5 KiB
Rust
use crate::app::App;
|
|
use crate::args::Args;
|
|
use crate::config::{get_db_path, load_config};
|
|
use crate::db::Database;
|
|
use chrono::{DateTime, Utc};
|
|
use clap::Parser;
|
|
use color_eyre::eyre::{Result, WrapErr};
|
|
use std::fs::create_dir_all;
|
|
|
|
mod actions;
|
|
mod app;
|
|
mod args;
|
|
mod config;
|
|
mod db;
|
|
mod magnet;
|
|
mod models;
|
|
mod notifications;
|
|
mod reddit_client;
|
|
mod report;
|
|
mod schema;
|
|
mod services;
|
|
|
|
/// Post information with magnet links
|
|
#[derive(Debug)]
|
|
pub struct PostInfo {
|
|
pub title: String,
|
|
pub submitter: String,
|
|
pub magnet_links: Vec<magnet::Magnet>,
|
|
pub subreddit: String,
|
|
pub timestamp: DateTime<Utc>,
|
|
pub imdb_id: Option<String>,
|
|
pub tags: Vec<String>,
|
|
}
|
|
|
|
#[tokio::main]
|
|
async fn main() -> Result<()> {
|
|
// Initialize error handling
|
|
color_eyre::install()?;
|
|
|
|
// Parse command-line arguments
|
|
let args = Args::parse();
|
|
|
|
// Initialize logging
|
|
pretty_env_logger::formatted_timed_builder()
|
|
.filter_level(args.verbose.log_level_filter())
|
|
.init();
|
|
|
|
// Initialize database
|
|
let db_path = get_db_path(&args)?;
|
|
|
|
// Create parent directory if it doesn't exist
|
|
if let Some(parent) = db_path.parent() {
|
|
create_dir_all(parent)
|
|
.wrap_err_with(|| format!("Failed to create directory: {:?}", parent))?;
|
|
}
|
|
|
|
let db = Database::new(&db_path)
|
|
.wrap_err_with(|| format!("Failed to initialize database at {:?}", db_path))?;
|
|
|
|
// Load configuration
|
|
let conf = load_config(&args)?;
|
|
|
|
// Create and run the application
|
|
App::new(db, conf).run(args.post_count).await?;
|
|
|
|
Ok(())
|
|
}
|