Skip to content

Instantly share code, notes, and snippets.

@iansltx
Created November 28, 2022 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iansltx/3ad242751760b4da9ff5820fea383813 to your computer and use it in GitHub Desktop.
Save iansltx/3ad242751760b4da9ff5820fea383813 to your computer and use it in GitHub Desktop.
Post Booster
<?php
// The script will keep its place based on a file called min_id, which should contain
// the ID of the post after which we should start boosting. If we don't specify an ID,
// we'll grab the latest 40 posts and boost them, writing the min_id file as we go
// through the list. So if you don't want to potentially duplicate boosts, make sure
// a status ID is in that file.
// To run this script, you'll need to install PHP. You can do that on an Ubuntu 22.04 box by running
// sudo apt install php-cli
// To run this script on a schedule, e.g. every minute, add a command to your crontab, via
// EDITOR=nano crontab -e
// and then add e.g.
// * * * * * php booster.php phpc.social php AUTH_TOKEN_HERE >> booster.log
// To get an auth token, go to /settings/applications, then click New Application,
// then fill out an application name, then select the write:statuses scope, then click
// Submit. Click the application once created, then grab the "Your access token" field.
if ($argc < 4) {
die("Usage: php booster.php domain tag auth-token\n");
}
[, $hostname, $tag, $token] = $argv;
$minId = file_exists('min_id') ? ('&min_id=' . file_get_contents('min_id')) : '';
$limit = 40;
$posts = json_decode(file_get_contents("https://$hostname/api/v1/timelines/tag/$tag?local=true&limit=$limit$minId"), true);
usort($posts, fn ($a, $b) => $a['id'] <=> $b['id']);
foreach ($posts as $post) {
$id = $post['id'];
echo "Boosting $id...";
if (file_get_contents(
"https://$hostname/api/v1/statuses/$id/reblog",
false,
stream_context_create([
'http' => [
'method' => 'POST',
'header' => "Authorization: Bearer $token"
]
]))) {
echo "done!\n";
file_put_contents('min_id', $id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment