2023-09-07 18:02:36 +01:00
|
|
|
mod processes;
|
|
|
|
mod services;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
2023-09-07 18:20:38 +01:00
|
|
|
use std::env;
|
|
|
|
|
2023-08-31 08:42:56 +01:00
|
|
|
use anyhow::Result;
|
2023-09-07 18:20:38 +01:00
|
|
|
use dotenv::dotenv;
|
2023-08-31 08:42:56 +01:00
|
|
|
|
2023-09-07 18:02:36 +01:00
|
|
|
use crate::processes::post_saver::PostSaver;
|
|
|
|
use crate::processes::profile_classifier::ProfileClassifier;
|
|
|
|
use crate::services::ai::AI;
|
|
|
|
use crate::services::bluesky::Bluesky;
|
|
|
|
use crate::services::database::Database;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
2023-09-07 18:20:38 +01:00
|
|
|
struct Config {
|
|
|
|
chat_gpt_api_key: String,
|
|
|
|
database_url: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Config {
|
|
|
|
fn load() -> Result<Self> {
|
|
|
|
dotenv()?;
|
|
|
|
|
|
|
|
Ok(Self {
|
|
|
|
chat_gpt_api_key: env::var("CHAT_GPT_API_KEY")?,
|
|
|
|
database_url: env::var("DATABASE_URL")?,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-18 20:11:49 +01:00
|
|
|
#[tokio::main]
|
2023-08-31 08:42:56 +01:00
|
|
|
async fn main() -> Result<()> {
|
2023-09-07 18:20:38 +01:00
|
|
|
let config = Config::load()?;
|
|
|
|
|
|
|
|
let ai = AI::new(&config.chat_gpt_api_key, "https://api.openai.com");
|
2023-09-07 18:02:36 +01:00
|
|
|
let bluesky = Bluesky::new("https://bsky.social");
|
2023-09-07 18:20:38 +01:00
|
|
|
let database = Database::connect(&config.database_url).await?;
|
2023-08-31 08:42:56 +01:00
|
|
|
|
2023-09-07 18:02:36 +01:00
|
|
|
let post_saver = PostSaver::new(&database, &bluesky);
|
|
|
|
let profile_classifier = ProfileClassifier::new(&database, &ai, &bluesky);
|
2023-09-06 07:26:03 +01:00
|
|
|
|
2023-09-07 18:02:36 +01:00
|
|
|
tokio::try_join!(post_saver.start(), profile_classifier.start())?;
|
2023-08-18 20:11:49 +01:00
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|