Made test mode post status only (and always) for the last announcement in the feed, instead of the first, thus checking as much as possible even the previous ones; refined output; minor changes; bumped version to 0.5.4
This commit is contained in:
parent
f20d07a2ee
commit
4f924226b6
1 changed files with 18 additions and 19 deletions
37
ganciof2f
37
ganciof2f
|
@ -18,7 +18,7 @@
|
|||
|
||||
$SNAME='GancioF2F';
|
||||
$ENAME=strtolower($SNAME);
|
||||
$SVERS='0.5.3';
|
||||
$SVERS='0.5.4';
|
||||
|
||||
require __DIR__.'/lib/ckmkeys.php';
|
||||
require __DIR__.'/lib/gettlds.php';
|
||||
|
@ -155,7 +155,7 @@ always_link_gancio_post = true
|
|||
-t / --test
|
||||
Do a test: {$SNAME} will try as always to read the configuration file, fetch
|
||||
the defined Mastodon instance’s info, load the state file and fetch the feed,
|
||||
but it will post only the first of the announcements it may find there, with
|
||||
but it will post only the last of the announcements it may find there, with
|
||||
a visibility of «direct», even if according to the state file it has already
|
||||
been posted, and won’t update the state file.
|
||||
This option also activates “verbose mode” (see below).
|
||||
|
@ -375,7 +375,7 @@ $tsfp="{$conf['state_file_absolute_path']}.tmp";
|
|||
if (!$opts['test'] && ($fh=@fopen($tsfp,'w'))===false) dieYoung("Error: could not open «{$tsfp}» in «write» mode.\n",1);
|
||||
$itemsToPost=0;
|
||||
$goodPostsCount=0;
|
||||
foreach ($feed as $item) {
|
||||
foreach ($feed as $index=>$item) {
|
||||
//print_r($item);
|
||||
$now=time();
|
||||
$postUrl="https://{$conf['feed_hostname']}/event/{$item['slug']}";
|
||||
|
@ -389,12 +389,13 @@ foreach ($feed as $item) {
|
|||
} else {
|
||||
$state='old';
|
||||
}
|
||||
// echo ($index+1)."/{$itemsCount}\n";
|
||||
// $state='new';
|
||||
if ($state=='old' && !$opts['test']) {
|
||||
if ($opts['do-post'])
|
||||
vecho($opts['verbose'],"Info: won’t try to post status for {$state} announcement «{$postUrl}».\n");
|
||||
if ($state=='old' && (!$opts['test'] || $index+1<$itemsCount)) {
|
||||
if ($opts['do-post'] && !$opts['test'])
|
||||
vecho($opts['verbose'],"Info: won’t try to post status for old announcement «{$postUrl}».\n");
|
||||
else
|
||||
vecho($opts['verbose'],"Info: wouldn’t try to post status for {$state} announcement «{$postUrl}».\n");
|
||||
vecho($opts['verbose'],"Info: wouldn’t try to post status for old announcement «{$postUrl}».\n");
|
||||
} else {
|
||||
$itemsToPost++;
|
||||
$postHead="{$item['title']}\n\n";
|
||||
|
@ -446,10 +447,12 @@ foreach ($feed as $item) {
|
|||
// echo "@@@ {$postUrl}: {$postLen} @@@\n{$post}\n---\n";
|
||||
if ($postLen>$conf['max_post_length']) {
|
||||
fwrite(STDERR,"Warning: could not shrink post for {$state} announcement «{$postUrl}» into {$conf['max_post_length']} characters; won’t try to post.\n");
|
||||
} elseif (!$opts['do-post'] && !$opts['test']) {
|
||||
} elseif (!$opts['do-post'] || ($opts['test'] && $index+1<$itemsCount)) {
|
||||
vecho($opts['verbose'],"Info: would try to post status for {$state} announcement «{$postUrl}».\n");
|
||||
if ($state=='new' || $state=='changed') $refs[$item['slug']]=['updatedAt'=>$item['updatedAt'], 'postedAt'=>time()];
|
||||
$goodPostsCount++;
|
||||
if (!$opts['test']) {
|
||||
$goodPostsCount++;
|
||||
if ($state=='new' || $state=='changed') $refs[$item['slug']]=['updatedAt'=>$item['updatedAt'], 'postedAt'=>time()];
|
||||
}
|
||||
} else {
|
||||
vecho($opts['verbose'],"Info: trying to post status for {$state} announcement «{$postUrl}».\n");
|
||||
$doPost=false;
|
||||
|
@ -542,24 +545,20 @@ foreach ($feed as $item) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (!$opts['test']) {
|
||||
if (array_key_exists($item['slug'],$refs)) fwrite($fh,"{$item['slug']}\t{$refs[$item['slug']]['updatedAt']}\t{$refs[$item['slug']]['postedAt']}\n");
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (!$opts['test'] && array_key_exists($item['slug'],$refs)) fwrite($fh,"{$item['slug']}\t{$refs[$item['slug']]['updatedAt']}\t{$refs[$item['slug']]['postedAt']}\n");
|
||||
}
|
||||
|
||||
if (!$opts['test']) {
|
||||
fclose($fh);
|
||||
rename($tsfp,$conf['state_file_absolute_path']);
|
||||
if ($opts['do-post'])
|
||||
vecho($opts['verbose'],"Info: succesfully posted {$goodPostsCount} of {$itemsToPost} statuses for new or changed announcement(s) (of {$itemsCount} total announcement(s) in the feed).\n");
|
||||
vecho($opts['verbose'],"Info: succesfully posted {$goodPostsCount} statuses for {$itemsToPost} new or changed announcement(s), out of a total of {$itemsCount} announcement(s) in the feed.\n");
|
||||
else
|
||||
vecho($opts['verbose'],"Info: would have tried to post {$itemsToPost} statuses for new or changed announcement(s) of {$itemsCount} total announcement(s) in the feed.\n");
|
||||
vecho($opts['verbose'],"Info: would have tried to post {$itemsToPost} statuses for new or changed announcement(s) out of a total of {$itemsCount} announcement(s) in the feed.\n");
|
||||
} elseif ($goodPostsCount==1) {
|
||||
vecho($opts['verbose'],"Info: successfully posted status for the first of {$itemsCount} total announcements in the feed.\n");
|
||||
vecho($opts['verbose'],"Info: successfully posted status for the last of {$itemsCount} total announcements in the feed; identified {$itemsToPost} new or changed announcement(s) to be posted.\n");
|
||||
} else {
|
||||
vecho($opts['verbose'],"Info: failed to post status for the first of {$itemsCount} total announcements in the feed.\n");
|
||||
vecho($opts['verbose'],"Info: failed to post status for the last of {$itemsCount} total announcements in the feed; identified {$itemsToPost} new or changed announcement(s) to be posted.\n");
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
|
Loading…
Reference in a new issue