Last active
April 5, 2020 22:15
-
-
Save jadiunr/afe975bb2fc2591da681f64ae710d24e to your computer and use it in GitHub Desktop.
Mastodonの鍵トゥを片っ端から消して回るスクリプト 自己責任
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use utf8; | |
use Furl; | |
use JSON qw/decode_json/; | |
$|=1; | |
my $domain = '<YOUR MASTODON DOMAIN>'; | |
my $access_token = '<YOUR MASTODON ACCESS TOKEN>'; | |
my $account_id = '<YOUR MASTODON ACCOUNT ID (number)>'; | |
my $fetch_statuses_interval = 2; # Limit: 300/5min(By default) | |
my $delete_status_interval = 61; # Limit: 30/30min(By default) | |
my $furl = Furl->new(headers => ['Authorization' => "Bearer ${access_token}"]); | |
my $max_id = '9223372036854775807'; #7FFFFFFFFFFFFFFF | |
my $fetched_statuses_count = 0; | |
my $deleted_statuses_count = 0; | |
while(1) { | |
sleep $fetch_statuses_interval; | |
my $statuses = decode_json($furl->get("https://${domain}/api/v1/accounts/${account_id}/statuses?limit=40&exclude_replies=false&max_id=${max_id}")->content); | |
$fetched_statuses_count += scalar(@$statuses); | |
print $fetched_statuses_count." statuses fetched\n"; | |
for my $status (@$statuses) { | |
if($status->{visibility} eq 'private') { | |
sleep $delete_status_interval; | |
$furl->delete("https://${domain}/api/v1/statuses/$status->{id}"); | |
$deleted_statuses_count++; | |
print "Deleted: $status->{id}, total: ${deleted_statuses_count}\n"; | |
} | |
} | |
last if scalar(@$statuses) < 40; | |
$max_id = $statuses->[-1]{id}; | |
} | |
print "Done\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment