Added the Fedi Appreciation Day script

This commit is contained in:
Koneko Toujou 2021-07-13 20:40:11 +01:00
parent 71e9e44c87
commit a10ba407df
No known key found for this signature in database
GPG Key ID: 61B8CE6DA2F634DA
1 changed files with 42 additions and 0 deletions

42
appreciation_day Normal file
View File

@ -0,0 +1,42 @@
#!/usr/bin/php
<?php
// Special Thanks to @avocatto@pleroma.paritybit.ca for suggesting this idea!
// Change these two variables for your instance!
$instance = 'landofkittens.social'; // The instance you're on, minus https:// (Only tested on Pleroma)
$account = '9yio7aRBggsrDkDobg'; // Your account id (this is not your username, pleroma api docs says it can be but never worked for me)
echo "Getting list of followers...\r\n";
if (!in_array('--no-cache', $argv) && file_exists(".{$account}_{$instance}_followers.cache.json")) {
$users = json_decode(file_get_contents(".{$account}_{$instance}_followers.cache.json"));
} else {
$check = true;
$users = [];
$max_id = '';
while ($check) {
$temp = json_decode(file_get_contents("https://$instance/api/v1/accounts/$account/followers?limit=40&max_id=$max_id"));
foreach ($temp as $user) {
$users[] = $user->acct;
$max_id = $user->id;
}
if (count($temp) !== 40) {
$check = false;
}
}
file_put_contents(".{$account}_{$instance}_followers.cache.json", json_encode($users));
}
echo "Choosing someone...\r\n";
// If we want a unique person per day, we hit this code
if (in_array('--day', $argv)) {
srand(date('mdy'));
}
echo "=== Today is @" . $users[rand(0,count($users) - 1)] . " appreciation day! ===\r\n";