diff --git a/run_with_log.sh b/run_with_log.sh new file mode 100755 index 0000000..413220c --- /dev/null +++ b/run_with_log.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +mastodon-image-uploader-bot >./tmp/log.out 2>./tmp/log.err +if [ ! -s ./tmp/log.err ]; then + echo -n "$(date +"[%Y-%M-%d %T]") success: " >> ./bot.log + cat ./tmp/log.out >> ./bot.log +else + echo -n "$(date +"[%Y-%M-%d %T]") errors: " >> ./bot.log + cat ./tmp/log.err >> ./bot.log +fi \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 0dddc20..bc1908c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,8 +78,8 @@ fn get_next_url(config: &Config) -> Option { .write(true) .append(true) // This is needed to append to file .open(&config.files.posted) - .unwrap(); - write!(file, "{}\n", urls[0]).unwrap(); + .expect("Cannot open posted file"); // Maybe we should retry just in case + write!(file, "{}\n", urls[0]).expect("Cannot write to posted file"); // maybe we should retry tbh Some(urls[0].to_string().clone()) } } @@ -101,8 +101,8 @@ async fn post_image(account: &Mastodon, url: &String, config: &Config) { .visibility(Visibility::Unlisted) .sensitive(true) .build() - .unwrap(); - account.new_status(status).await.expect("Error generating status"); + .expect("Could not build status"); // we should retry + account.new_status(status).await.expect("Error generating status"); // we should retry or delete last url in posted println!("Status posted") } @@ -127,9 +127,9 @@ async fn update_bio(account: &Mastodon, config: &Config) { ), ]) .spawn() - .unwrap() + .expect("Could not spawn curl") .wait() - .unwrap(); + .expect("Curl failed"); } async fn post(account: &Mastodon, msg: &str) {