221 líneas
6,2 KiB
PHP
221 líneas
6,2 KiB
PHP
|
<?php
|
||
|
if (!empty($_SERVER["argv"][1])){
|
||
|
$argument = $_SERVER["argv"][1];
|
||
|
} else {
|
||
|
// Presenta l'ajuda
|
||
|
echo "NO HE REBUT la variable\n";
|
||
|
echo "Cal el directori on s'executa el bot_plus.\n";
|
||
|
exit;
|
||
|
}
|
||
|
$lloc = $argument;
|
||
|
|
||
|
// ara podrá carregar la configuració i el logger
|
||
|
include("".$lloc."/configuracio/bot_plus_cfg.php");
|
||
|
include("".$lloc."/utils/bot_plus_funcions.php");
|
||
|
require_once("".$lloc."/lib/logger.php");
|
||
|
|
||
|
// inicia el log
|
||
|
$log = new Logging();
|
||
|
$log->lfile("".$log_fitxer."");
|
||
|
|
||
|
$fitxer = $lloc."/fitxers/seguidors_detall_act.json";
|
||
|
$json_dec = json_decode(file_get_contents($fitxer), true);
|
||
|
|
||
|
$maxim = count($json_dec);
|
||
|
$e = 1;
|
||
|
//$v = 1;
|
||
|
for($e=1;$e<$maxim;$e++) {
|
||
|
//$usua = $json_dec[$e]['usuari'];
|
||
|
//$nom = $json_dec[$e]['nom'];
|
||
|
$acct = $json_dec[$e]['acct'];
|
||
|
$inst = explode("@", $acct);
|
||
|
//$crea = $json_dec[$e]['creat'];
|
||
|
//$publ = $json_dec[$e]['ult_pub'];
|
||
|
//print_r($inst);
|
||
|
if( (count($inst)==1) ) {
|
||
|
$inst_t = "mastodont.cat";
|
||
|
} else {
|
||
|
$inst_t = $inst[1];
|
||
|
}
|
||
|
// echo $inst_t."\n";
|
||
|
// $v++;
|
||
|
$inst_matriu[] = $inst_t ;
|
||
|
}
|
||
|
|
||
|
//print_r($inst_matriu);
|
||
|
$inst_mat_ord = array_count_values($inst_matriu);
|
||
|
arsort($inst_mat_ord);
|
||
|
|
||
|
//print_r(($inst_mat_ord));
|
||
|
|
||
|
// llegeix el nombre de seguidors
|
||
|
$nseg_lle = fopen($lloc."/fitxers/seg_cont.txt", "r") or die("No puc obrir el nombre seguidors!");
|
||
|
$nseg_ant = fread($nseg_lle,filesize($lloc."/fitxers/seg_cont.txt"));
|
||
|
fclose($nseg_lle);
|
||
|
|
||
|
|
||
|
$a = 0;
|
||
|
$part0 = "Els seguidors del compte son a: \n";
|
||
|
//echo "El seguidors son: \n";
|
||
|
foreach ($inst_mat_ord as $clau => $valor) {
|
||
|
// echo "$valor de $clau\n";
|
||
|
// $mat_inst_f[] = array('nom' => $clau, 'nombre' => $valor);
|
||
|
$mat_inst_f[$clau] = $valor." (".round( (($valor/$nseg_ant)*100) ,2)."%) de " .$clau. "\n";
|
||
|
$a++;
|
||
|
}
|
||
|
//echo "En total de ".$a." ".(($a<>1)?"instàncies diferents":"instància")."\n";
|
||
|
//echo "Moltes gràcies!! :cli_root: \n";
|
||
|
//print_r($mat_inst_f);
|
||
|
|
||
|
$part1 = implode("",$mat_inst_f);
|
||
|
|
||
|
$part2 = "En total de ".$a." ".(($a<>1)?"instàncies diferents":"instància")."\n" .
|
||
|
"#SocUnBot \n".
|
||
|
"Moltes gràcies!! :cli_root: \n".
|
||
|
$bot_nom." v".$bot_versio;
|
||
|
|
||
|
$tut = $part0."".$part1."".$part2."\n";
|
||
|
//echo $tut;
|
||
|
//echo strlen($tut)." caracters \n";
|
||
|
$lletres = strlen($tut);
|
||
|
|
||
|
$linies_tut = substr_count($tut, "\n");
|
||
|
//echo "linies_tut: ".$linies_tut."\n";
|
||
|
|
||
|
$nlin = 16;
|
||
|
if($a>=$nlin) {
|
||
|
|
||
|
// $pasada = round($a/$nlin,0);
|
||
|
$pasada = ceil($a/$nlin);
|
||
|
// echo "Cal fer ".$pasada." tuts\n";
|
||
|
|
||
|
for($r=1;$r<$pasada;$r++) {
|
||
|
$tut_complet = $tut;
|
||
|
$linies = explode("\n", $tut_complet);
|
||
|
if($r==1) {
|
||
|
$linies = array_slice($linies, 0, $nlin*$r); //18 is how many lines you want to keep
|
||
|
} else {
|
||
|
$linies = array_slice($linies, $nlin*($r-1), $nlin); //18 is how many lines you want to keep
|
||
|
}
|
||
|
$tut_frag = implode("\n", $linies);
|
||
|
// echo "linies: ".$nlin*$r."\n";
|
||
|
// echo "Tut nº".$r."\n".$tut_frag."\n";
|
||
|
// echo strlen($tut_frag)." caracters \n";
|
||
|
// sleep(1);
|
||
|
// publicacio per fer els tuts que calga, sempre múltiple de nlin
|
||
|
if($r == 1) {
|
||
|
// echo "primer tut\n";
|
||
|
$tut_data = array(
|
||
|
"status" => $tut_frag,
|
||
|
"language" => $llengua,
|
||
|
"visibility" => $visib_imp_res
|
||
|
);
|
||
|
// print_r($tut_data);
|
||
|
} else {
|
||
|
// echo "tut nº".$r."\n";
|
||
|
$tut_data = array(
|
||
|
"status" => $tut_frag,
|
||
|
"language" => $llengua,
|
||
|
"visibility" => $visib_imp_res,
|
||
|
"in_reply_to_id" => $mes_comp_id
|
||
|
);
|
||
|
// print_r($tut_data);
|
||
|
}
|
||
|
|
||
|
// no es pot aplicar la funció. no retrona el id per fer la resposta o fil.
|
||
|
// PublicaMissatge($base_url,$headers,$tut_data);
|
||
|
$bot_conn = curl_init();
|
||
|
curl_setopt($bot_conn, CURLOPT_URL, $base_url . "/api/v1/statuses");
|
||
|
curl_setopt($bot_conn, CURLOPT_POST, 1);
|
||
|
curl_setopt($bot_conn, CURLOPT_POSTFIELDS, $tut_data);
|
||
|
curl_setopt($bot_conn, CURLOPT_HTTPHEADER, $headers);
|
||
|
curl_setopt($bot_conn, CURLOPT_RETURNTRANSFER, true);
|
||
|
// $resposta_in = curl_exec($bot_conn);
|
||
|
// $resposta_conn = json_decode($resposta_in,true);
|
||
|
$resposta_conn = json_decode(curl_exec($bot_conn),true);
|
||
|
curl_close ($bot_conn);
|
||
|
|
||
|
// echo "resposta del servidor\n";
|
||
|
// print_r($resposta_conn);
|
||
|
$mes_comp_id = $resposta_conn['id'];
|
||
|
sleep(1);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
$log->lwrite("Estadistiques de les instàncies dels seguidors publicades");
|
||
|
exit;
|
||
|
|
||
|
|
||
|
if($lletres > 480) {
|
||
|
//echo "fragmentar en dos la cadena i fer dos tuts \n";
|
||
|
|
||
|
//fragmente la cadena
|
||
|
$tut0 = strlen($tut) > 480 ? substr($tut,0,486)."[...]" : $tut;
|
||
|
$tut1 = strlen($tut) > 480 ? substr($tut,486,$lletres) : $tut;
|
||
|
//echo "tut0: ".$tut0."\n";
|
||
|
//echo "tut1: ".$tut1."\n";
|
||
|
|
||
|
// fer tut i segon en resposta a
|
||
|
// publique el primer tut
|
||
|
$tut_data = array(
|
||
|
"status" => $tut0,
|
||
|
"language" => $llengua,
|
||
|
"visibility" => $visib_imp_res
|
||
|
);
|
||
|
|
||
|
$ch_status = curl_init();
|
||
|
curl_setopt($ch_status, CURLOPT_URL, $base_url . "/api/v1/statuses");
|
||
|
curl_setopt($ch_status, CURLOPT_POST, 1);
|
||
|
curl_setopt($ch_status, CURLOPT_POSTFIELDS, $tut_data);
|
||
|
curl_setopt($ch_status, CURLOPT_RETURNTRANSFER, true);
|
||
|
curl_setopt($ch_status, CURLOPT_HTTPHEADER, $headers);
|
||
|
$output_status = json_decode(curl_exec($ch_status),true);
|
||
|
curl_close ($ch_status);
|
||
|
// $mr++;
|
||
|
|
||
|
//print_r($output_status);
|
||
|
// consulte el id del tut per fer el segon
|
||
|
$mes_comp_id = $output_status['id'];
|
||
|
|
||
|
// publique el segon tut
|
||
|
$tut_data = array(
|
||
|
"status" => $tut1,
|
||
|
"language" => $llengua,
|
||
|
"visibility" => $visib_imp_res,
|
||
|
"in_reply_to_id" => $mes_comp_id
|
||
|
);
|
||
|
|
||
|
$ch_status = curl_init();
|
||
|
curl_setopt($ch_status, CURLOPT_URL, $base_url . "/api/v1/statuses");
|
||
|
curl_setopt($ch_status, CURLOPT_POST, 1);
|
||
|
curl_setopt($ch_status, CURLOPT_POSTFIELDS, $tut_data);
|
||
|
curl_setopt($ch_status, CURLOPT_RETURNTRANSFER, true);
|
||
|
curl_setopt($ch_status, CURLOPT_HTTPHEADER, $headers);
|
||
|
$output_status = json_decode(curl_exec($ch_status),true);
|
||
|
curl_close ($ch_status);
|
||
|
// $mr++;
|
||
|
|
||
|
} else {
|
||
|
//echo $tut."\n";
|
||
|
|
||
|
// publique un tut amb menys dels caràcter màxims
|
||
|
|
||
|
$tut_data = array(
|
||
|
"status" => $tut,
|
||
|
"language" => $llengua,
|
||
|
"visibility" => $visib_imp_res
|
||
|
);
|
||
|
|
||
|
$ch_status = curl_init();
|
||
|
curl_setopt($ch_status, CURLOPT_URL, $base_url . "/api/v1/statuses");
|
||
|
curl_setopt($ch_status, CURLOPT_POST, 1);
|
||
|
curl_setopt($ch_status, CURLOPT_POSTFIELDS, $tut_data);
|
||
|
curl_setopt($ch_status, CURLOPT_RETURNTRANSFER, true);
|
||
|
curl_setopt($ch_status, CURLOPT_HTTPHEADER, $headers);
|
||
|
$output_status = json_decode(curl_exec($ch_status),true);
|
||
|
curl_close ($ch_status);
|
||
|
|
||
|
}
|
||
|
|
||
|
?>
|