refactor: add info/debug

This commit is contained in:
VC
2022-11-08 08:37:53 +01:00
parent c62f67c3b3
commit 3c64df23bc
2 changed files with 9 additions and 8 deletions

View File

@@ -20,7 +20,7 @@ pub use state::{init_db, migrate_db};
use state::{read_state, write_state, TweetToToot}; use state::{read_state, write_state, TweetToToot};
use elefren::{prelude::*, status_builder::StatusBuilder}; use elefren::{prelude::*, status_builder::StatusBuilder};
use log::{debug, info}; use log::info;
use rusqlite::Connection; use rusqlite::Connection;
use std::sync::Arc; use std::sync::Arc;
use tokio::{spawn, sync::Mutex}; use tokio::{spawn, sync::Mutex};
@@ -48,7 +48,7 @@ pub async fn run(config: Config) {
let task_conn = conn.clone(); let task_conn = conn.clone();
let task = spawn(async move { let task = spawn(async move {
debug!("Starting treating {}", &mastodon_config.twitter_screen_name); info!("Starting treating {}", &mastodon_config.twitter_screen_name);
// retrieve the last tweet ID for the username // retrieve the last tweet ID for the username
let lconn = task_conn.lock().await; let lconn = task_conn.lock().await;
@@ -81,7 +81,7 @@ pub async fn run(config: Config) {
feed.reverse(); feed.reverse();
for tweet in &feed { for tweet in &feed {
debug!("Treating Tweet {} inside feed", tweet.id); info!("Treating Tweet {} inside feed", tweet.id);
// initiate the toot_reply_id var // initiate the toot_reply_id var
let mut toot_reply_id: Option<String> = None; let mut toot_reply_id: Option<String> = None;
// determine if the tweet is part of a thread (response to self) or a standard response // determine if the tweet is part of a thread (response to self) or a standard response
@@ -113,7 +113,7 @@ pub async fn run(config: Config) {
status_text = status_text.replace(&media_url, ""); status_text = status_text.replace(&media_url, "");
debug!("Building corresponding Mastodon status"); info!("Building corresponding Mastodon status");
let mut status_builder = StatusBuilder::new(); let mut status_builder = StatusBuilder::new();

View File

@@ -31,6 +31,8 @@ pub async fn generate_media_ids(
// size of media_ids vector, should be equal to the media vector // size of media_ids vector, should be equal to the media vector
media_ids.resize(m.media.len(), String::new()); media_ids.resize(m.media.len(), String::new());
info!("{} medias in tweet", m.media.len());
for (i, media) in m.media.iter().enumerate() { for (i, media) in m.media.iter().enumerate() {
// attribute media url // attribute media url
media_url = media.url.clone(); media_url = media.url.clone();
@@ -41,10 +43,7 @@ pub async fn generate_media_ids(
let mastodon = mastodon.clone(); let mastodon = mastodon.clone();
let task = tokio::task::spawn(async move { let task = tokio::task::spawn(async move {
<<<<<<< HEAD
=======
info!("Start treating {}", media.media_url_https); info!("Start treating {}", media.media_url_https);
>>>>>>> 32f9605 (tamerelol)
// get the tweet embedded media // get the tweet embedded media
let local_tweet_media_path = match get_tweet_media(&media, &cache_path).await { let local_tweet_media_path = match get_tweet_media(&media, &cache_path).await {
Ok(l) => l, Ok(l) => l,
@@ -65,7 +64,7 @@ pub async fn generate_media_ids(
return Err(ScootalooError::new(&format!( return Err(ScootalooError::new(&format!(
"Attachment {} cannot be uploaded to Mastodon Instance: {}", "Attachment {} cannot be uploaded to Mastodon Instance: {}",
&local_tweet_media_path, e &local_tweet_media_path, e
))) )));
} }
}; };
@@ -88,6 +87,8 @@ pub async fn generate_media_ids(
Err(e) => error!("Something went wrong when joining the main thread: {}", e), Err(e) => error!("Something went wrong when joining the main thread: {}", e),
} }
} }
} else {
info!("No media in tweet");
} }
// in case some media_ids slot remained empty due to errors, remove them // in case some media_ids slot remained empty due to errors, remove them