Browse Source

Handle boosts

pull/1/head
Toromino 3 years ago
parent
commit
bcf0fa9a33
  1. 8
      Cargo.toml
  2. 51
      src/main.rs

8
Cargo.toml

@ -5,9 +5,9 @@ authors = ["Toromino <foxhkron@toromino.de>"] @@ -5,9 +5,9 @@ authors = ["Toromino <foxhkron@toromino.de>"]
edition = "2018"
[dependencies]
chrono = { version = "0.4", features = ["serde"] }
chrono = { version = "0.4.10", features = ["serde"] }
getopts = "0.2.21"
reqwest = { version = "0.10.1", features = ["json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
tokio = { version = "0.2", features = ["full"] }
serde = { version = "1.0.104", features = ["derive"] }
serde_json = "1.0.44"
tokio = { version = "0.2.9", features = ["full"] }

51
src/main.rs

@ -49,17 +49,34 @@ impl Credentials { @@ -49,17 +49,34 @@ impl Credentials {
struct Status {
id: String,
created_at: String,
reblog: Option<Box<Status>>,
}
impl Status {
async fn delete(&self, client: &reqwest::Client, url: &str, token: &str) {
client
.delete(&format!("https://{}/api/v1/statuses/{}", url, &self.id))
.header("Authorization", &format!("Bearer {}", &token))
.send()
.await
.expect("An error occured while deleting a status");
println!("Successfully deleted status '{}'", &self.id);
match &self.reblog {
Some(reblog) => {
client
.delete(&format!(
"https://{}/api/v1/statuses/{}/unreblog",
url, &reblog.id
))
.header("Authorization", &format!("Bearer {}", &token))
.send()
.await
.expect("An error occured while deleting a share");
println!("Successfully deleted share of '{}'", &reblog.id);
}
None => {
client
.delete(&format!("https://{}/api/v1/statuses/{}", url, &self.id))
.header("Authorization", &format!("Bearer {}", &token))
.send()
.await
.expect("An error occured while deleting a status");
println!("Successfully deleted status '{}'", &self.id);
}
}
}
}
@ -274,6 +291,20 @@ async fn main() { @@ -274,6 +291,20 @@ async fn main() {
);
let timestamp = prompt().parse::<NaiveDate>().unwrap();
println!("Should Pubcleaner also delete shares/boosts/announces? (y/N)");
let delete_shares = if &prompt() == "y" { true } else { false };
let fmt_shares = if delete_shares { " and shares" } else { "" };
println!(
"You want to delete statuses{} older than {}. Is that correct? (y/N)",
fmt_shares, &timestamp
);
println!("WARNING: All data will be deleted PERMANENTLY!");
if prompt() != "y" {
panic!("Aborted!")
};
let mut counter: i32 = 0;
let mut last_largest_id: Option<String> = None;
loop {
@ -288,8 +319,10 @@ async fn main() { @@ -288,8 +319,10 @@ async fn main() {
.timestamp()
< NaiveDateTime::new(timestamp, NaiveTime::from_hms(0, 0, 0)).timestamp()
{
status.delete(&client, &url, &access_token).await;
counter += 1;
if (delete_shares && status.reblog.is_some()) || status.reblog.is_none() {
status.delete(&client, &url, &access_token).await;
counter += 1;
}
}
}

Loading…
Cancel
Save