Subir archivos a ''

This commit is contained in:
bonobo 2023-05-24 10:44:30 +02:00
pare 9238ddc508
commit 608859a118
S'han modificat 1 arxius amb 185 adicions i 0 eliminacions

185
bot_plus_utils.php Normal file
Veure arxiu

@ -0,0 +1,185 @@
<?php
// Comprova els arguments, en cas de no existir presenta l'ajuda.
if (!empty($_SERVER["argv"][1])){
$argument = $_SERVER["argv"][1];
if($argument == "-ctemps") {
$data = 0;
if(!empty($_SERVER["argv"][2])) {
$data = $_SERVER["argv"][2];
} else {
presenta_ajuda();
exit;
}
}
} else {
// Presenta l'ajuda
//$opcio = getopt("i::hp::");
//print_r($opcio);
presenta_ajuda();
exit;
}
//defineix on es troba el fitxer a executar
$lloc = realpath(dirname(__FILE__));
include("configuracio/bot_plus_cfg.php");
if ($argument == "-imp") {
$impuls = shell_exec("php utils/bot_plus_consultaimpulsos.php ".$lloc);
echo $impuls."\n";
}
elseif ($argument == "-impj") {
$impuls_json = shell_exec("php proves/proves_impulsos_json_cli.php ".$lloc);
echo $impuls_json."\n";
}
elseif ($argument == "-fitxs") {
$data_pu = shell_exec("wc -l fitxers/dates.txt");
$data_bc = shell_exec("wc -l fitxers/dates.bak");
$urls_pu = shell_exec("wc -l fitxers/urls_pub.txt");
$urls_bc = shell_exec("wc -l fitxers/urls_pub.bak");
$imps_rg = shell_exec("wc -l fitxers/impulsos.txt");
$menc_rg = shell_exec("wc -l fitxers/mencions.txt");
echo "LINIES DELS FITXERS \n";
echo $data_pu;
echo $data_bc;
echo $urls_pu;
echo $urls_bc."\n";
echo $imps_rg."";
echo $menc_rg."\n";
}
elseif ($argument == "-mencs") {
//include("proves/proves_mencions_json.php");
$mencions = shell_exec("php ".$lloc."/proves/proves_mencions_json_cli.php ".$lloc);
echo $mencions."\n";
}
elseif ($argument == "-info") {
//include("proves/proves_mencions_json.php");
echo "La versió actual és la ".$bot_versio."\n";
$d_pub = shell_exec("cat ".$lloc."/fitxers/data_pub.txt");
echo "La darrera publicació l'he feta el ".date("d/m/Y",$d_pub)." a les ".date("H:i:s",$d_pub)."\n";
echo "Els fixers estan a ".$lloc."\n";
$data_pu = shell_exec("wc -l fitxers/dates.txt");
$data_bc = shell_exec("wc -l fitxers/dates.bak");
$urls_pu = shell_exec("wc -l fitxers/urls_pub.txt");
$urls_bc = shell_exec("wc -l fitxers/urls_pub.bak");
$imps_rg = shell_exec("wc -l fitxers/impulsos.txt");
$menc_rg = shell_exec("wc -l fitxers/mencions.txt");
echo "\nLINIES DELS FITXERS \n";
echo $data_pu;
echo $data_bc;
echo $urls_pu;
echo $urls_bc."\n";
echo $imps_rg."";
echo $menc_rg."\n";
$errada = shell_exec("cat ".$lloc."/fitxers/errada_cont.txt");
echo "En ".$errada." voltes no he pogut connectar per obtindre la font xml o RSS.\n";
$seguid = shell_exec("cat fitxers/seg_cont.txt");
$seguidc = shell_exec("cat fitxers/cents_cont.txt");
echo "\n".$seguid." seguidors actualment\n";
echo $seguidc. " és el máxim de seguidors. (cents) \n";
}
elseif ($argument == "-graf") {
$graf_est = shell_exec("/usr/bin/php -f ".$lloc."/utils/bot_plus_fergrafic.php ".$lloc."/");
$graf_imp = shell_exec("php ".$lloc."/utils/bot_plus_fergrafic_imp.php ".$lloc."/");
//echo $inst_est;
}
elseif ($argument == "-inst") {
$inst_est = shell_exec("php proves/proves_estadistiques_seguidors_nopub.php ".$lloc);
echo $inst_est;
}
elseif ($argument == "-ctemps") {
$dataconv = shell_exec("php utils/bot_plus_convdate.php ".$data);
echo $dataconv."\n";
}
elseif ($argument == "-vvars") {
$matvars = get_defined_vars();
ksort($matvars);
print_r($matvars);
}
elseif ($argument == "-segs") {
$seguid = shell_exec("cat fitxers/seg_cont.txt");
$seguidd = shell_exec("wc -l fitxers/seguidors.txt");
$seguidc = shell_exec("cat fitxers/cents_cont.txt");
$seg_m = explode(" ",$seguidd);
echo $seguid." seguidors actualment\n";
echo $seg_m[0]. " seguidors segons el fitxer de registre.\n";
echo $seguidc. " és el máxim de seguidors. (cents) \n";
if($seguid<>$seg_m[0]) {
echo "Convé revisar els fitxers.\n";
} else {
echo "Correcte.\n";
echo "\nVols revisar els seguidors un a un? (Si/No)\n";
$handle = fopen ("php://stdin","r");
$line = fgets($handle);
if( (trim($line) != 'Si') ){
echo "HE ACABAT DONCS!\n";
exit;
}
fclose($handle);
echo "\n";
echo "Gràcies, els repassem...\n";
include("proves/proves_seguidors_json.php");
// $det_segs = shell_exec("php proves/proves_seguidors_json.php ".$lloc);
// echo $det_segs;
}
} elseif ($argument == "-asegs") {
$act_segs = shell_exec("php proves/proves_activitat_seguidors_nopub.php ".$lloc);
echo $act_segs."\n";
} elseif ($argument == "-ajuda"){
echo "Estes on les opcions disponibles de \n";
presenta_ajuda();
}
else {
echo "\nLA OPCIÓ ÉS INCORRECTA.\n\n";
presenta_ajuda();
exit;
}
/**
$opcions_curtes = "i::m::s::a::n::";
$opcions_llargues = ["impulsos::", "mencions::", "seguidors::", "activitat::", "instancia::" ];
$opcions = getopt($opcions_curtes, $opcions_llargues);
if(isset($opcions["i"]) || isset($opcions["impulsos"])) {
echo "he rebut la opció impulsos en versió ";
if(isset($opcions["i"])) {
echo "curta.\n";
} else {
echo "llarga.\n";
}
}
**/
function presenta_ajuda() {
echo "bot_plus_utils per bonobo <@bonobo@mastodont.cat>.\n\n";
echo "Ús de ".$_SERVER["argv"][0]." \n";
echo "Esta és la plana d'utilitats.\n";
echo "Pots triar entre les següents opcions: \n";
echo "\t -ajuda \tPresenta esta plana d'ajuda.\n";
echo "\t -info \tPresenta informació útil del funcionament del bot: darrera publicació, errades,....\n";
echo "\t -imp \tConsulta els impulsos guardats fins el moment i els presenta per pantalla.\n";
echo "\t -impj \tConsulta els impulsos guardats fins el moment i els presenta i actualitza el fitxer json.\n";
echo "\t -mencs \tActualitza el fitxer json de mencions al bot.\n";
echo "\t -graf \tGenera els gràfics del resum setmanal.(en proves)\n";
echo "\t -segs \tEt mostra el nombre de seguidors actuals del compte.\n";
echo "\t -asegs \tEt la estadística per setmanes de la darrera publicació de tuts dels seguidors.\n";
echo "\t -inst \tEstadistica de quina instància son els seguidors.\n";
echo "\t -fitxs \tEt mostra el nombre de linies dels fitxers de control del bot.\n";
echo "\t -ctemps \tConverteix el temps a diferents format per si vols consultar o modificar-ho en alguna part de la programació.\n";
echo "\t \tAmb esta opció cal afegir la data en format 'Sun, 12 Mar 2023 12:55:00 +0100' i entre cometes.\n";
echo "\t -vvars \tPer veure les variables del fitxer.(?)\n";
echo "Exemple per a utilitzar ".$_SERVER["argv"][0]."\n";
echo "\t /el/cami/fins/la/carpeta/".$_SERVER["argv"][0]." -opció\n";
echo "Espere que't siga util. 😉 \n";
}
?>