From bf70072376abc39a664babb6d8f13a80639794c3 Mon Sep 17 00:00:00 2001 From: VC Date: Wed, 8 Nov 2023 10:00:34 +0100 Subject: [PATCH] ready to roll --- src/lib.rs | 17 +++++++++++++---- src/twitter.rs | 20 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 src/twitter.rs diff --git a/src/lib.rs b/src/lib.rs index 900dd4a..f003d2f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,7 +3,8 @@ pub use config::{parse_toml, Config}; mod state; pub use state::init_db; -use state::read_state; +#[allow(unused_imports)] +use state::{read_state, write_state}; mod mastodon; use mastodon::get_mastodon_timeline_since; @@ -12,6 +13,10 @@ pub use mastodon::register; mod utils; use utils::strip_everything; +mod twitter; +#[allow(unused_imports)] +use twitter::{post_tweet, upload_media}; + use rusqlite::Connection; #[tokio::main] @@ -29,9 +34,13 @@ pub async fn run(config: &Config) { for toot in timeline { let Ok(tweet_content) = strip_everything(&toot.content, &toot.tags) else { - continue; + continue; // skip in case we can’t strip something }; - println!("Toot: {}", toot.id); - println!("{:?}", tweet_content); + // if we wanted to cut toot in half, now would be the right time to do so + // treating medias (nothing for now) + let _tweet_id = post_tweet(&tweet_content, &[]) + .await + .unwrap_or_else(|e| panic!("Cannot Tweet {}: {}", toot.id, e)); + return; } } diff --git a/src/twitter.rs b/src/twitter.rs new file mode 100644 index 0000000..1670426 --- /dev/null +++ b/src/twitter.rs @@ -0,0 +1,20 @@ +use serde::{Deserialize, Serialize}; +use std::error::Error; + +#[derive(Serialize, Debug)] +pub struct Tweet {} + +#[derive(Deserialize, Debug)] +pub struct TweetResponse {} + +/// This function uploads media from Mastodon to Twitter and returns the media id from Twitter +#[allow(dead_code)] +pub async fn upload_media(_u: &str) -> Result> { + Ok(0) +} + +/// This posts Tweets with all the associated medias +#[allow(dead_code)] +pub async fn post_tweet(_content: &str, _medias: &[u64]) -> Result> { + Ok(0) +}