A script to download and parse Anti-Meta Fedi Pact’s list of instances blocking Threads; first commit
This commit is contained in:
parent
6789b7379c
commit
6a53523a87
1 changed files with 101 additions and 0 deletions
101
web/clitools/fedipact.php
Executable file
101
web/clitools/fedipact.php
Executable file
|
@ -0,0 +1,101 @@
|
|||
#!/usr/bin/php
|
||||
<?php
|
||||
|
||||
/*
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
define('N',"\n");
|
||||
require __DIR__.'/../lib/delinstbyid.php';
|
||||
$levs=['Debug', 'Info', 'Warning', 'Error'];
|
||||
|
||||
$opts=[
|
||||
'url'=>'https://fedipact.online/',
|
||||
'ofpath'=>__DIR__.'/fedipact.list'
|
||||
];
|
||||
|
||||
$help='mustool.php
|
||||
DESCRIPTION
|
||||
fedipact.php downloads the list of Anti-Meta Fedi Pact signers from
|
||||
«'.$opts['url'].'», parses it, creates a machine readable signers list and
|
||||
saves it to «'.$opts['ofpath'].'».
|
||||
SYNOPSIS
|
||||
fedipact.php
|
||||
OPTIONS
|
||||
-h, --help
|
||||
Shows this help text and exits.
|
||||
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details see the source.
|
||||
This is free software, and you are welcome to redistribute it under
|
||||
certain conditions; see <http://www.gnu.org/licenses/> for details.'.N;
|
||||
|
||||
for ($i=1; $i<$argc; $i++) {
|
||||
if ($argv[$i]=='-h' || $argv[$i]=='--help') {
|
||||
echo($help);
|
||||
exit(0);
|
||||
} else {
|
||||
mexit('don’t know how to interpret «'.$argv[$i].'» (use «-h» to read help).'.N,1);
|
||||
}
|
||||
}
|
||||
|
||||
$cont=@file($opts['url'],FILE_IGNORE_NEW_LINES|FILE_SKIP_EMPTY_LINES);
|
||||
if (is_array($cont)) {
|
||||
$domlist=[];
|
||||
foreach ($cont as $line)
|
||||
if (preg_match('#<li>\s*🖤\s*[a-z0-9\.\-\_]+@([a-z0-9\.\-\_]+)\s*</li>#iu',$line,$matches)===1)
|
||||
if (!in_array($matches[1],$domlist))
|
||||
$domlist[]=mb_strtolower($matches[1]);
|
||||
$cdomlist=count($domlist);
|
||||
if ($cdomlist>0) {
|
||||
sort($domlist);
|
||||
$domlist=implode(N,$domlist);
|
||||
if (@file_put_contents($opts['ofpath'],$domlist.N)===false)
|
||||
mexit('couldn’t save domain list into «'.$opts['ofpath'].'» :-('.N,3);
|
||||
else
|
||||
eecho('done saving '.$cdomlist.' entries into «'.$opts['ofpath'].'» :-)'.N,1);
|
||||
} else {
|
||||
mexit('couldn’t find any domain in «'.$opts['url'].'» :-('.N,2);
|
||||
}
|
||||
} else {
|
||||
mexit('couldn’t open «'.$opts['url'].'».'.N,3);
|
||||
}
|
||||
|
||||
exit(0);
|
||||
|
||||
|
||||
// functions
|
||||
|
||||
function mexit($msg,$code) {
|
||||
global $link;
|
||||
if (isset($link) && $link!==false) mysqli_close($link);
|
||||
if ($code==0)
|
||||
eecho($msg,1);
|
||||
else
|
||||
eecho($msg,3);
|
||||
exit($code);
|
||||
}
|
||||
|
||||
function eecho($msg,$lev=1) {
|
||||
global $levs;
|
||||
$time=microtime(false);
|
||||
$time=explode(' ',$time);
|
||||
$time=date('Y-m-d H:i:s',$time[1]).'.'.substr($time[0],2);
|
||||
$msg=$time.' '.$levs[$lev].': '.$msg;
|
||||
if ($lev<2)
|
||||
echo($msg);
|
||||
else
|
||||
fwrite(STDERR,$msg);
|
||||
}
|
||||
|
||||
?>
|
Loading…
Reference in a new issue