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 mastodon_async::helpers::toml; // requires `features = ["toml"]`
use mastodon_async::prelude::*;
use std::process::Command;
use mastodon_async::helpers::toml; use mastodon_async::scopes;
use mastodon_async::{prelude::*, UpdateCredsRequest};
use mastodon_async::{entities::visibility::Visibility};
use mastodon_async::{helpers::cli, Result};
use mastodon_async::{helpers::cli};
use reqwest;
use std::io::Cursor;
use std::io::Write;
@ -16,7 +17,10 @@ async fn main() -> Result<()> {
};
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
};
@ -53,6 +57,25 @@ async fn post_image(account: &Mastodon, url: &String) {
.build()
.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) {
@ -75,7 +98,7 @@ async fn fetch_url(url: String, file_name: String) -> Result<()> {
async fn register() -> Result<Mastodon> {
let registration = Registration::new("https://awoo.fai.st")
.client_name("sleeping-girls-bot")
.scopes(Scopes::all())
.scopes(Scopes::write(scopes::Write::Accounts))
.build()
.await?;
let mastodon = cli::authenticate(registration).await?;