215 líneas
6,8 KiB
PHP
215 líneas
6,8 KiB
PHP
<?php
|
|
if (!empty($_SERVER["argv"][1])){
|
|
$argument = $_SERVER["argv"][1];
|
|
$ferfil = $_SERVER["argv"][2];
|
|
$pub = $_SERVER["argv"][3];
|
|
} 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/impulsos.json";
|
|
$json_dec = json_decode(file_get_contents($fitxer), true);
|
|
//print_r($json_dec);
|
|
$maxim = count($json_dec);
|
|
|
|
$k = 0;
|
|
//$ui_tot = 0;
|
|
for($k=0;$k<$maxim;$k++) {
|
|
$usu_imp = $json_dec[$k]['qui'];
|
|
$usu_mat[] = $usu_imp;
|
|
}
|
|
//print_r($usu_mat);
|
|
$usu_mat_ord = array_count_values($usu_mat);
|
|
arsort($usu_mat_ord);
|
|
|
|
//print_r($usu_mat_ord);
|
|
|
|
$l = 0;
|
|
$top = count($usu_mat_ord);
|
|
$usu_inv_mat = array();
|
|
|
|
foreach ($usu_mat_ord as $clau => $valor) {
|
|
$usu_nom = explode("@",$clau);
|
|
if( (count($usu_nom)==1) ) {
|
|
$inst_t = "mastodont.cat";
|
|
} else {
|
|
$inst_t = $usu_nom[1];
|
|
}
|
|
|
|
$usu_inv_mat[] += $valor;
|
|
$usu_ins_mat[] = [$inst_t => $valor];
|
|
$usu_per_mat[] = [$usu_nom[0], $valor];
|
|
}
|
|
|
|
$pers_matriu = array_column($usu_per_mat, '1', '0');
|
|
//print_r($pers_matriu);
|
|
$pers_tot = count($pers_matriu);
|
|
|
|
$sum_insta = array();
|
|
array_walk_recursive($usu_ins_mat, function($item, $key) use (&$sum_insta){
|
|
$sum_insta[$key] = isset($sum_insta[$key]) ? $item + $sum_insta[$key] : $item;
|
|
});
|
|
|
|
//echo "sum_insta";
|
|
arsort($sum_insta);
|
|
//print_r($sum_insta);
|
|
$sum_inst_mtr = array();
|
|
$sum_total = 0;
|
|
foreach ($sum_insta as $clau => $valor) {
|
|
// echo $valor." impulsos des de ".$clau."\n";
|
|
// $sum_inst_mtr[] = $valor." des de " .$clau. "\n";
|
|
$sum_total += $valor;
|
|
}
|
|
foreach ($sum_insta as $clau => $valor) {
|
|
// echo $valor." impulsos des de ".$clau."\n";
|
|
// $sum_inst_mtr[] = $valor." des de " .$clau. "\n";
|
|
$sum_inst_mtr[] = $valor." (".round((($valor/$sum_total)*100),2)."%) des de " .$clau. "\n";
|
|
// $sum_total += $valor;
|
|
}
|
|
|
|
if ($pub !=0) {
|
|
goto elaboracio;
|
|
} else {
|
|
exit;
|
|
}
|
|
|
|
elaboracio:
|
|
|
|
$seguid = shell_exec("cat ".$lloc."/fitxers/seg_cont.txt");
|
|
$a = count($sum_insta);
|
|
|
|
$part0 = "Els impulsos s'han fet: \n";
|
|
$part1 = implode("",$sum_inst_mtr);
|
|
$part2 = "Un total de ".$pers_tot." ".(($pers_tot<>1)?"persones han":"persona ha")." impulsat des de ".$a." ".(($a<>1)?"instàncies diferents":"instància").
|
|
" i representen el ".round(($pers_tot/$seguid)*100,2)."% sobre els seguidors.\n";
|
|
|
|
$part3 = "Amb un total de ".$sum_total." impulsos (favorits i reblocs)\n".
|
|
"Moltes gràcies!.\n".
|
|
"#SocUnBot #ResumSetmanal";
|
|
|
|
$tut = $part0."".$part1."".$part2."".$part3."\n";
|
|
//echo $tut;
|
|
|
|
$lletres = strlen($tut);
|
|
//echo $lletres." caracters \n";
|
|
|
|
$linies_tut = substr_count($tut, "\n");
|
|
|
|
$nlin = 11;
|
|
if($linies_tut>=$nlin) {
|
|
|
|
$pasada = ceil($linies_tut/$nlin);
|
|
|
|
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";
|
|
// echo substr_count($tut_frag,"\n")." linies \n";
|
|
// echo $linies_tut." linies \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" => $ferfil
|
|
);
|
|
// 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);
|
|
$ferfil = $resposta_conn['id'];
|
|
sleep(1);
|
|
//echo $tut_frag;
|
|
}
|
|
|
|
} else {
|
|
// publica només un tut
|
|
echo $tut;
|
|
//echo strlen($tut)." caracters \n";
|
|
//echo "linies_tut: ".$linies_tut."\n";
|
|
|
|
$tut_data = array(
|
|
"status" => $tut,
|
|
"language" => $llengua,
|
|
"visibility" => $visib_imp_res,
|
|
"in_reply_to_id" => $ferfil
|
|
|
|
);
|
|
|
|
// 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);
|
|
$ferfil = $resposta_conn['id'];
|
|
|
|
}
|
|
//print_r($resposta_conn);
|
|
//exit;
|
|
// aqui per que a impulsos em dona errada tot i que ho fa
|
|
$log -> lwrite("INFO: fer tut instàncies d'impulsos: ".( (($ferfil != null)||($ferfil != false))?"correcte":"ERRADA")."");
|
|
|
|
// fer tuts de impulsos i favorits per dies de la setmana
|
|
//$graf_imp_setm = shell_exec("/usr/bin/php -f ".$lloc."/proves/bot_plus_estadistiques_inst_impulsos.php ".$lloc." ".$ferfil." 1" );
|
|
$graf_imp_setm = shell_exec("/usr/bin/php -f ".$lloc."/utils/bot_plus_graficsxdies.php ".$lloc." ".$ferfil."");
|
|
$log -> lwrite("INFO: fer tut gràfics per dies: ".( (($graf_imp_setm != null)||($graf_imp_setm != false))?"correcte":"ERRADA")."");
|
|
|
|
?>
|