remaining images in bio

This commit is contained in:
Suguivy 2023-03-09 20:23:56 +01:00
parent 950fe918b8
commit 43c11d1957
1 changed files with 28 additions and 5 deletions

View File

@ -1,8 +1,9 @@
use std::collections::HashSet; use std::collections::HashSet;
use mastodon_async::helpers::toml; // requires `features = ["toml"]` use std::process::Command;
use mastodon_async::prelude::*; use mastodon_async::helpers::toml; use mastodon_async::scopes;
use mastodon_async::{prelude::*, UpdateCredsRequest};
use mastodon_async::{entities::visibility::Visibility}; use mastodon_async::{entities::visibility::Visibility};
use mastodon_async::{helpers::cli, Result}; use mastodon_async::{helpers::cli};
use reqwest; use reqwest;
use std::io::Cursor; use std::io::Cursor;
use std::io::Write; use std::io::Write;
@ -16,7 +17,10 @@ async fn main() -> Result<()> {
}; };
match get_next_url() { match get_next_url() {
Some(url) => post_image(&mastodon, &url).await, Some(url) => {
post_image(&mastodon, &url).await;
update_bio(&mastodon).await;
},
None => post(&mastodon, "@Sugui@awoo.fai.st @MeDueleLaTeta@awoo.fai.st me quedé sin chicas").await None => post(&mastodon, "@Sugui@awoo.fai.st @MeDueleLaTeta@awoo.fai.st me quedé sin chicas").await
}; };
@ -53,6 +57,25 @@ async fn post_image(account: &Mastodon, url: &String) {
.build() .build()
.unwrap(); .unwrap();
account.new_status(status).await.unwrap(); account.new_status(status).await.unwrap();
}
async fn update_bio(account: &Mastodon) {
let binding = std::fs::read("./posted.csv").expect("File not found").iter().map(|c| *c as char).collect::<String>();
let posted = binding.lines().collect::<HashSet<_>>();
let binding = std::fs::read("./urls.csv").expect("File not found").iter().map(|c| *c as char).collect::<String>();
let urls = binding.lines().collect::<HashSet<_>>();
let remaining = urls.difference(&posted).count();
Command::new("curl")
.args([
"-X", "PATCH",
"https://awoo.fai.st/api/v1/accounts/update_credentials",
"-H", &format!("Authorization:Bearer {}", account.data.token),
"-d", &format!("note=Bot who posts images of sleeping girls every 6 hours.\n\n{} new images remaining", remaining),
]).spawn().unwrap().wait().unwrap();
} }
async fn post(account: &Mastodon, msg: &str) { async fn post(account: &Mastodon, msg: &str) {
@ -75,7 +98,7 @@ async fn fetch_url(url: String, file_name: String) -> Result<()> {
async fn register() -> Result<Mastodon> { async fn register() -> Result<Mastodon> {
let registration = Registration::new("https://awoo.fai.st") let registration = Registration::new("https://awoo.fai.st")
.client_name("sleeping-girls-bot") .client_name("sleeping-girls-bot")
.scopes(Scopes::all()) .scopes(Scopes::write(scopes::Write::Accounts))
.build() .build()
.await?; .await?;
let mastodon = cli::authenticate(registration).await?; let mastodon = cli::authenticate(registration).await?;