Add Mastodon toot exporter
This commit is contained in:
parent
324ffdeb19
commit
e58b111280
2 changed files with 50 additions and 0 deletions
45
PatchMastodon.php
Executable file
45
PatchMastodon.php
Executable file
|
|
@ -0,0 +1,45 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
require('MastodonBotPHP/Mastodon.php');
|
||||
require('PatchObject.php');
|
||||
require('Database.php');
|
||||
require('MastodonKey.php');
|
||||
|
||||
function timestamp() {
|
||||
$f = fopen(__DIR__ . '/timestamp-mastodon.dat', 'a+');
|
||||
flock($f, LOCK_EX);
|
||||
$t = fgets($f);
|
||||
ftruncate($f, 0);
|
||||
fwrite($f, time());
|
||||
fflush($f);
|
||||
flock($f, LOCK_UN);
|
||||
fclose($f);
|
||||
return intval($t);
|
||||
}
|
||||
|
||||
$db = new Database(__DIR__ . '/db.json');
|
||||
if (!$db->load()) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
$last = timestamp();
|
||||
|
||||
$mastodon = new MastodonAPI($MastodonAccessToken, 'https://botsin.space');
|
||||
|
||||
for ($i = 0; $i < $db->count(); $i++) {
|
||||
$patch = $db->get($i);
|
||||
if ($last < $patch->getTimestamp()) {
|
||||
$s = $patch->getVendor() . ' released #' . $patch->getProduct();
|
||||
if (!empty($patch->getBranch()))
|
||||
$s .= ' ' . $patch->getBranch();
|
||||
$s .= ' version ' . $patch->getVersion() . '.';
|
||||
$len = strlen($s) + 24; // + space + wrapped URL
|
||||
$s .= ' ' . $patch->getURL();
|
||||
echo $patch->getId() . ': ' . $len . PHP_EOL;
|
||||
$dat = ['status' => $s];
|
||||
$mastodon->postStatus($dat);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue