diff --git a/utils/bot_plus_cents.php b/utils/bot_plus_cents.php new file mode 100644 index 0000000..71038da --- /dev/null +++ b/utils/bot_plus_cents.php @@ -0,0 +1,228 @@ +lfile(''.$log_fitxer.''); + +$log->lwrite("Arranque decenes/centears de seguidors."); + +// preparatius i variables comunes +// obtindre el meu perfil per saber el nombre de seguidors + + $bot_status = curl_init(); + curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/accounts/109436876995250353"); + curl_setopt($bot_status, CURLOPT_RETURNTRANSFER, true); + curl_setopt($bot_status, CURLOPT_HTTPHEADER, $headers); + $resposta = (curl_exec($bot_status)); + $resposta_json = json_decode(curl_exec($bot_status)); + curl_close ($bot_status); +// var_dump($resposta); +// echo "resposta\n"; +// print_r($resposta); + $resposta = json_decode($resposta,true); +// echo "\n\nresposta json_decode\n"; +// print_r($resposta); + +// triar les variables que volem de la matriu + +$tcc = microtime(true); +$dcon = $tcc - $tc; +echo "Temps cents conn: ".round($dcon,4)."\n"; + +$seguidors = $resposta['followers_count']; +$instancia = "https://mastodont.cat"; +$pub_cent = null; +$pub_img = null; + +if ( (is_int($seguidors/100))||(is_int($seguidors/10)) ) { + + if(is_int($seguidors/100)) { $n_gif = $seguidors; + } else { $centenar = floor($seguidors/100); + $desenes = ($seguidors - ($centenar*100)); + $n_gif = $desenes; + } + $pub_cent = "Ja en sou ".$seguidors." persones seguint el compte 🎂 a ".$instancia.". Moltes gràcies! :brindis: #SocUnBot\n".$bot_nom." v".$bot_version." "; +// $pub_img = "/home/nachobg/privado/mastodon-rss-bot-plus/gifis/".$n_gif.".gif"; + $pub_img = $lloc."/gifis/".$n_gif.".gif"; + + $fitxer_tipus = mime_content_type($pub_img); + $fitxer_prep = curl_file_create($pub_img, $fitxer_tipus, 'file'); + echo "fitxer_tipus: ".$fitxer_tipus."\n"; +// sleep(1); + +} else { + echo "Son ".$seguidors.". La condició es que siga multiple de 100 redó i ara fa ".($seguidors/100)."\n"; +} + +$pub_img = $lloc."/gifis/".$n_gif.".gif"; +$fitxer_tipus = mime_content_type($pub_img); + +$publica_img = array( + "file" => $pub_img, + "type"=> $fitxer_tipus, + "description" => "Celebració pels ".$seguidors." seguidors." + ); + +//print_r($publica_img); +//echo "mostrat matriu publica_img\n"; +//sleep(4); + +$publ_img = json_encode($publica_img); +//echo "publ_img: ".$publ_img."\n"; +//echo "mostrat publ_img\n"; +//sleep(4); + +// publicar (copiat de bot.php) +if ($pub_cent != null) { + +/** // Publica a Mastodon + $headers = [ + 'Authorization: Bearer ' . $token + ]; +**/ + $status_data = array( + "status" => $pub_cent, + "text" => $pub_cent, + "language" => $llengua, + "visibility" => $visib_com + ); + +$pub_img = $lloc."/gifis/".$n_gif.".gif"; +$fitxer_tipus = mime_content_type($pub_img); +$fitxer_prep = curl_file_create($pub_img, $fitxer_tipus, 'file'); + +$publica_img = [ 'file' => $fitxer_prep, 'description' => 'Celebració pels '.$seguidors.' seguidors.', 'text' => $pub_cent, 'status' => 'Prova de missatge amb imatge des del bot' ]; + +// pujada de la imatge + $ch_status = curl_init(); + curl_setopt($ch_status, CURLOPT_URL, $base_url . "/api/v2/media"); + curl_setopt($ch_status, CURLOPT_POST, 1); + curl_setopt($ch_status, CURLOPT_POSTFIELDS, $publica_img); + 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); +// $p++; + +echo "\n\nresposta media : \n"; +print_r ($output_status); +$imat_mst = $output_status['id']; +$imat_url = $output_status['url']; + +//echo "id de la imatge pujada: ".$imat_mst."\n"; +sleep(1); +// PujaImatges($base_url,$imat_mst,$headers,$bot_status); + + $bot_status = curl_init(); + curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/media/".$imat_mst.""); + curl_setopt($bot_status, CURLOPT_RETURNTRANSFER, true); + curl_setopt($bot_status, CURLOPT_HTTPHEADER, $headers); + $resposta = (curl_exec($bot_status)); + $resposta_json = json_decode(curl_exec($bot_status)); + curl_close ($bot_status); +// var_dump($resposta); +// echo "resposta\n"; +// print_r($resposta); + $resposta = json_decode($resposta,true); +// echo "\n\nresposta json_decode\n"; +// print_r($resposta); + +echo "obtenció dades media: \n"; +//print_r($resposta_json); +sleep(1); + +$im_id = $resposta['id']; +$im_url = $resposta['url']; +$im_type = $resposta['type']; +$im_desc = $resposta['description']; + +//sleep(10); + +$img_bis = $lloc."/gifis/".$n_gif.".gif"; + +$imatge_adj = array('file' => $im_url, 'type' => $im_type, 'description' => $im_desc); +$imatge_adj_json = json_encode($imatge_adj); + + $status_data2 = array( + "status" => $pub_cent, + "language" => $llengua, + "visibility" => $visib_com + ); + +// funció per enviar matriu en matriu + +function http_build_query_for_curl( $arrays, &$new = array(), $prefix = null ) { + + if ( is_object( $arrays ) ) { + $arrays = get_object_vars( $arrays ); + } +/** + foreach ( $arrays AS $key => $value ) { + $k = isset( $prefix ) ? $prefix . '[' . $key . ']' : $key; + if ( is_array( $value ) OR is_object( $value ) ) { + http_build_query_for_curl( $value, $new, $k ); + } else { + $new[$k] = $value; + } + } +**/ + foreach ( $arrays AS $key => $value ) { + $k = isset( $prefix ) ? $prefix . '[' . $key . ']' : $key; + if ( is_array( $value ) OR is_object( $value ) ) { + http_build_query_for_curl( $value, $new, $k ); + } else { + $new[$k] = $value; + } + } + +} + +$tut_matriu = array( + "status" => $pub_cent, + "text" => $pub_cent, + "language" => $llengua, + "media_ids[]" => $im_id, + "visibility" => $visib_cent, + "sensitive" => null, + "spoiler_text" => null, + "in_reply_to_id" => null +); + +http_build_query_for_curl( $tut_matriu, $tut_dades ); + +// comentat per no publicar proves funció +// PublicaMissatge($headers,$base_url,$tut_dades); + $pub_text_imat = curl_init(); + curl_setopt($pub_text_imat, CURLOPT_URL, $base_url . "/api/v1/statuses"); + curl_setopt($pub_text_imat, CURLOPT_POST, 1); + curl_setopt($pub_text_imat, CURLOPT_POSTFIELDS, $tut_dades); + curl_setopt($pub_text_imat, CURLOPT_RETURNTRANSFER, true); + curl_setopt($pub_text_imat, CURLOPT_HTTPHEADER, $headers); + $resposta_img_txt = json_decode(curl_exec($pub_text_imat),true); + curl_close ($pub_text_imat); +// $p++; + +} + +$estad_segs = shell_exec("/usr/bin/php -f ".$lloc."/proves/proves_estadistiques_seguidors.php ".$lloc); +if ( ($estad_segs == null)||($estad_segs == false) ) { + $log -> lwrite("INFO: estadistiques de seguidors: ".(($estad_segs != null)?"correcte":"ERRADA").""); +} + +$tcf = microtime(true); +$dc = $tcf - $tc; +echo "Temps cents dins: ".round($dc,4)."\n"; +?> diff --git a/utils/bot_plus_comentaris.php b/utils/bot_plus_comentaris.php new file mode 100644 index 0000000..c5cef99 --- /dev/null +++ b/utils/bot_plus_comentaris.php @@ -0,0 +1,173 @@ +lfile(''.$log_fitxer.''); + +// per quan trasllade aqui la decisió de fer el comentari des de bot_plus +$log->lwrite("Estan activats els comentaris."); +$arrancat = 0; +//$log->lwrite("lloc rebut: ".$lloc.""); +//$log->lwrite("data_ina: ".$data_ina." - data_dif: ".$data_dif.""); +if ( $data_ina >= $data_dif) { + $log -> lwrite("Arranque comentaris: ".$data_ina." (".gmdate("H:i:s", ($data_ina))." h)"); + $arrancat = 1; + // obtindre els perfils dels seguidors cal curl + // GET https://mastodon.example/api/v1/accounts/:id/followers HTTP/1.1 + $instancia = "mastodont.cat"; + $creador = "https://mastodont.cat/@bonobo"; + $inscrit = "1/12/2022"; + +// activar comentari (private) als seguidors d'inactivitat +// llegir data de la darrera publicació + $com_lle = fopen($lloc."/fitxers/com_pub.txt", "r") or die("No puc obrir la darrera data!"); + $com_ant = fread($com_lle,filesize($lloc."/fitxers/com_pub.txt")); + fclose($com_lle); + $espera_coment2 = strtotime($espera_coment2); + $com_ara2 = strtotime("now"); + $com_ara3 = ($com_ara2 + rand(-3,3)); +// echo "com_ant: ".$com_ant."\n"; +// echo "com_com: ".$espera_coment."\n"; +// echo "com_ara: ".$com_ara."\n"; + $com_dif = ($espera_coment2 - $com_ara2); +// echo "com_dif: ".$com_dif."\n"; + $com_ina = ($com_ara2 - $com_ant); +// echo "Inactiu el comentari: ".$com_ina." | ".date("H:i:s",($com_ina-3600))." h | ".$com_dif." \n"; +// echo "data_ina: ".$data_ina."\n"; +// $inact_pub = $com_ina + 28800; +// echo "inact_pub: ".$inact_pub."\n"; + if ($com_ina > $com_dif) { +// echo "Active - temps superat = ".($com_ina > $com_dif)."\n"; + // publique sequencialment un missatge per inactivitat + + //cal triar un nombre pel divisor. Només si la divisió dona numero sencer es publicarà. (1 tots, 2 la meitat, 3 un de cada tres, ...) + $data_ina_mod = $data_ina + (rand(-300,300)); + $publicacio = null; + if ( is_int($com_ara3/7)) { +// $dic = "Soc ".$bot_nom.". Continue actiu, :cli_user: amb la versió ".$bot_versio." i vaig registrar-me el ".$inscrit.".\nAra fa ".date("H:i:s",($data_ina_mod-HoraGmt()))." hores que no hi han novetats per publicar de ".$web_of." 🖥️ .\n#SocUnBot 🤖"; + $directori = $lloc."/fitxers/"; + $compta_fitxers = count(glob($directori . "*")); + $fitxers = shell_exec("du -h -s ".$directori); + $fit_mat = str_split($fitxers, 4); + //echo "There were $compta_fitxers"; + $dic = "Fa ".gmdate("H:i:s",$data_ina_mod)." hores que no publique tuts d'actualitat de ".$web_of.".\n". + "Als meus fitxers, ".$compta_fitxers." en tinc, guarde ".$fit_mat[0]." de dades.\n". + "#SocUnBot\n". + $bot_nom." v".$bot_versio."\n"; + } elseif ( is_int($com_ara3/5)) { + $dic = ":cli_user: Continue actiu des del ".$inscrit.".\nAra fa ".gmdate("H:i:s",($data_ina_mod))." hores que no hi ha novetats per publicar. 🖥️ ".$bot_nom." v".$bot_versio." \n#SocUnBot 🤖"; + } elseif ( is_int($com_ara3/3)) { +// $dic = "La darrera publicació la vaig fer fa ".date("H:i:s",($data_ina_mod-HoraGmt()))."\n".$bot_nom." ".$bot_versio." :cli_user:.\n#SocUnBot 🤖"; + $sensors = shell_exec("sensors"); + $faig_ma = explode("\n",$sensors); + $dic = "La darrera publicació la vaig fer fa ".gmdate("H:i:s",($data_ina_mod))."\n". + "Esta és la temperatura dels meus processadors :cli_user:.\n". + $faig_ma[3]."\n". + $faig_ma[4]."\n". + "#SocUnBot\n". + $bot_nom." v".$bot_versio."\n"; + } elseif ( is_int($com_ara3/2)) { +// $dic = " ".$bot_nom." ".$bot_versio."\n".date("H:i:s",($data_ina_mod-HoraGmt()))." sense publicar novetats de ".$web_of." 🖥️ .\n#SocUnBot 🤖"; + $prev_oratge = shell_exec("ansiweather_mst -a false -l Aigües,ES -H true -s true -d true"); + $faig_m = explode("-",$prev_oratge); + $dic = "Fa ".gmdate("H:i:s",($data_ina_mod))." que no he publicat cap tut.\n". + "Esta és la previsió de l'oratge ara mateix a la localitat on està el meu servidor. :cli_user:\n". + $faig_m[0]."\n". + $faig_m[1]."\n". + $faig_m[2]."\n". + $faig_m[3]."\n". + $faig_m[4]."\n". + $faig_m[5]."\n". + $faig_m[6]."\n". + $faig_m[7]."\n". +// $faig_m[8]."\n". + "#SocUnBot #Oratge\n". + $bot_nom." v".$bot_versio."\n"; + } else { +// $dic = "ping 🖥️ .\nTemps d'inactivitat:".date("H:i",$data_ina)."\n #SocUnBot "; + $dic = "ping 🖥️ .\n ".$bot_nom." v".$bot_versio."\n#SocUnBot"; + } + $publicacio = $dic; +// echo "publicació: ".$publicacio."\n"; + + if ($publicacio != null) { +// echo "Entre a publicar es cert - ".($publicacio != null)."\n"; +// $log->lwrite("Entre a publicar ".($publicacio != null).""); + // publicar (copiat de bot.php) + // Publica a Mastodon +// $headers = [ +// 'Authorization: Bearer ' . $token +// ]; + + $dades_tut = array( + "status" => $publicacio, + "language" => $llengua, + "visibility" => $visib_com + ); +// echo print_r($status_data); +// $log->lwrite(print_r($status_data)); + PublicaMissatge($base_url,$headers,$dades_tut); + +// echo "matriu resposta: \n"; +// echo print_r($comentari_resposta)."\n"; + + // guarde la data de publicació de comentari + // actualitze strtotime del comentari publicat + $com_t = fopen("".$lloc."/fitxers/com_pub.txt", "w") or die("No puc obrir la darrera data!"); +// $com_tem = fread($com_t,filesize("".$lloc."/fitxers/com_pub.txt")); + $nou_tem = strtotime("now"); +// echo "nou_tem: ".$nou_tem."\n"; + fwrite($com_t, $nou_tem); + fclose($com_t); + +// echo "comentari (bis): ".$publicacio.""; + $log->lwrite($publicacio); + } else { +// echo "No active "; +// echo "No publique per pausa interna."; + $log->lwrite("No publique per pausa interna."); + // no fer res + } + +} else { +//echo "Inactiu el comentari: ".$com_ina." | ".date("H:i:s",($com_ina-3600))." h | ".$com_dif." \n"; +// llegir el temps de publicació de comentari i calcular el que resta per pausa interna + if($arrancat == 1) { + $log->lwrite("Inactiu el comentari: ".$com_ina." (".gmdate("H:i:s",($com_ina))." h) | ".$com_dif." (".gmdate("H:i:s",($com_dif) ).")"); + } +} + +// final condició temps inactivitat +} +//if ( (($data_dif - $data_ina) <= 3900)&&(($data_dif - $data_ina) < $espera_coment2) ) { +if ( (($data_dif - $data_ina) <= 3840) ) { +// diferenciar entre pausa de publicació (externa) i el temps d'espera entre comentaris. (PER FER) +// $log->lwrite("A ".date("H:i:s",($data_dif-$data_ina)-HoraGmt())." hores d'arrancar els comentaris."); + if($arrancat == 0) { + $log->lwrite("A ".gmdate("H:i:s",($data_dif-$data_ina))." hores d'arrancar els comentaris."); + } +} + +$tcf = microtime(true); +$dc = $tcf - $tc; +//echo "\nTemps comentari dins: ".round($dc,4)." "; +$log->lwrite("Temps comentari: ".round($dc,4).""); +?> diff --git a/utils/bot_plus_funcions.php b/utils/bot_plus_funcions.php new file mode 100644 index 0000000..cd13066 --- /dev/null +++ b/utils/bot_plus_funcions.php @@ -0,0 +1,202 @@ + $val) { + if ($val['id'] == $id) { + return $key; + } + } + return null; +} + +function errorExec($resposta) { + if ($resposta !=0) { + $missatge = "!ERRADA!"; + } else { + $missatge = "Correcte"; + } + return $missatge; +} + +function TriaOpcio($num) { + + if (is_int($num/23)) { $trie = 1; } + elseif (is_int($num/19)) { $trie = 2; } + elseif (is_int($num/17)) { $trie = 3; } + elseif (is_int($num/13)) { $trie = 4; } + elseif (is_int($num/11)) { $trie = 5; } + elseif (is_int($num/7 )) { $trie = 6; } + elseif (is_int($num/5 )) { $trie = 7; } + elseif (is_int($num/3 )) { $trie = 8; } + elseif (is_int($num/2 )) { $trie = 9; } + else { $trie = 10; } + + return $trie; +} + +function enviaCorreu($elmeucompte,$titol,$contingut,$elremitent) { + $per = $elmeucompte; + $assumpte = $titol; + $missatge = $contingut; + $de = $elremitent; + $caps = "From:" . $de . ""; + + mail($per,$assumpte,$missatge,$caps); +} + +function canviaVariableFitxer($path, $oldContent, $newContent) +{ + $str = file_get_contents($path); + $str = str_replace($oldContent, $newContent, $str); + file_put_contents($path, $str); +} +// utilitzacio +// canviaVariableFiter('your file path','string you want to change', 'new string') + +// connexió mencions +function ConsultaNotificacions($token,$base_url,$limit_m,$headers) { + + $bot_status = curl_init(); + curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/notifications?limit=".$limit_m.""); + curl_setopt($bot_status, CURLOPT_RETURNTRANSFER, true); + curl_setopt($bot_status, CURLOPT_HTTPHEADER, $headers); + $resposta = (curl_exec($bot_status)); + $resposta_json = json_decode(curl_exec($bot_status),true); + curl_close ($bot_status); + $resposta = json_decode($resposta,true); +// echo "\n\nresposta json_decode\n"; +// print_r($resposta); +// $nr = count($resposta); +// echo $nr."\n"; +return $resposta; + +} + +function ConsultaMencions($token,$base_url,$limit_m,$headers) { +//Link: ; rel="next", ; + $bot_status = curl_init(); + curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/notifications?limit=".$limit_m.""); +// curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/notifications?types[]=mention"); + curl_setopt($bot_status, CURLOPT_RETURNTRANSFER, true); + curl_setopt($bot_status, CURLOPT_HTTPHEADER, $headers); + $resposta = (curl_exec($bot_status)); + $resposta_json = json_decode(curl_exec($bot_status),true); + curl_close ($bot_status); + $resposta = json_decode($resposta,true); +// echo "\n\nresposta json_decode\n"; +// print_r($resposta); +// $nr = count($resposta); +// echo $nr."\n"; + +return $resposta; +} + + +function ConsultaSeguidors($base_url,$id_cmpt,$headers) { + + $bot_perf = curl_init(); + curl_setopt($bot_perf, CURLOPT_URL, $base_url . "/api/v1/accounts/".$id_cmpt.""); + curl_setopt($bot_perf, CURLOPT_RETURNTRANSFER, true); + curl_setopt($bot_perf, CURLOPT_HTTPHEADER, $headers); + $bot_dad = (curl_exec($bot_perf)); + $bot_dad_json = json_decode(curl_exec($bot_perf)); + curl_close ($bot_perf); + $bot_dad = json_decode($bot_dad,true); + $seg_bot = $bot_dad['followers_count']; + +//return $bot_dad; +return $seg_bot; +} + +// PROVES +// connexió imatges +function PujaImatges($base_url,$imat_mst,$headers) { + + +} + +function RecuperaImatge($base_url,$imat_mst,$headers) { + +$bot_imtg = curl_init(); +curl_setopt($bot_imtg, CURLOPT_URL, $base_url . "/api/v1/media/".$imat_mst.""); +curl_setopt($bot_imtg, CURLOPT_RETURNTRANSFER, true); +curl_setopt($bot_imtg, CURLOPT_HTTPHEADER, $headers); +$resposta = (curl_exec($bot_imtg)); +$resposta_json = json_decode(curl_exec($bot_imtg)); +$resposta_imtg = json_decode($resposta,true); +curl_close ($bot_imtg); + +return $resposta_imtg; +} + +// connexio statuses +// per publicar +function PublicaMissatge($base_url,$headers,$publicacio) { + +$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, $publicacio); +curl_setopt($bot_conn, CURLOPT_RETURNTRANSFER, true); +curl_setopt($bot_conn, CURLOPT_HTTPHEADER, $headers); +$resposta_conn = json_decode(curl_exec($bot_conn),true); +curl_close ($bot_conn); + +return $resposta_conn; +} + +function FesFavorit($base_url,$en_resposta,$headers) { + +$fav_status = curl_init(); +curl_setopt($fav_status, CURLOPT_URL, $base_url . "/api/v1/statuses/".$en_resposta."/favourite"); +curl_setopt($fav_status, CURLOPT_POST, 1); +curl_setopt($fav_status, CURLOPT_RETURNTRANSFER, true); +curl_setopt($fav_status, CURLOPT_HTTPHEADER, $headers); +$fav_eixida = json_decode(curl_exec($fav_status),true); +curl_close ($fav_status); + +return $fav_eixida; +} + +function FesRebloc($base_url,$en_resposta,$headers) { + +$reb_status = curl_init(); +curl_setopt($reb_status, CURLOPT_URL, $base_url . "/api/v1/statuses/".$en_resposta."/reblog"); +curl_setopt($reb_status, CURLOPT_POST, 1); +curl_setopt($reb_status, CURLOPT_RETURNTRANSFER, true); +curl_setopt($reb_status, CURLOPT_HTTPHEADER, $headers); +$reb_eixida = json_decode(curl_exec($reb_status),true); +curl_close ($reb_status); + +return $reb_eixida; +} + +/** +// NO FUNCIONA ENCARA +function FesFinal() { + $neteja = shell_exec("tail -".$max_linies." ".$lloc."/fitxers/dates.txt | sort | uniq | tee ".$lloc."/fitxers/dates.txt"); + $net_url = shell_exec("tail -".($max_linies*2)." ".$lloc."/fitxers/urls_pub.txt | sort | uniq | tee ".$lloc."/fitxers/urls_pub.txt"); + $log -> lwrite("Temps total: ".date("i:s",$durada)." minuts | ".round($durada,4)." segons "); + $log -> lwrite ("FINAL!! ".$bot_nom." ".$bot_versio.""); + exit; +} +**/ +?> diff --git a/utils/bot_plus_impulsos.php b/utils/bot_plus_impulsos.php new file mode 100644 index 0000000..e9396bf --- /dev/null +++ b/utils/bot_plus_impulsos.php @@ -0,0 +1,490 @@ +lfile(''.$log_fitxer.''); + +$log->lwrite("Estàn activades les estadistiques dels impulsos."); + +// preparatius i variables comunes +$resposta = ConsultaNotificacions($token,$base_url,$limit_i,$headers); + +$tcc = microtime(true); +$dcon = $tcc - $tc; + +$temps_imp = strtotime("now"); +$espera_ob = fopen($lloc . "/fitxers/impulsos_temps.txt", "r") or die("No puc obrir la darrera data!"); +$espera_ll = fread($espera_ob,filesize($lloc . "/fitxers/impulsos_temps.txt")); +$espera_imp = $espera_ll; +fclose($espera_ob); + +// prova +//$espera_imp = strtotime("now"); + +$temps_ini = $espera_imp - 604800; + +$nr = count($resposta); + +$menc_mat = array(); +$d = 0; +for ($d = 0; $d < $nr; $d++) { +// triar les variables que volem de la matriu + $men_id = $resposta[$d]['id']; + $impuls = $resposta[$d]['type']; + $quan = $resposta[$d]['created_at']; + $qui = $resposta[$d]['account']['acct']; + if(!isset($resposta[$d]['status']['id'])) { + $mis_id = 0; + } else { + $mis_id = $resposta[$d]['status']['id']; + } + if ( ($impuls == "reblog")||($impuls == "favourite") ) { + $menc_mat[] = array ( 'id' => $men_id, 'mis_id' => $mis_id, 'qui' => $qui, 'impuls' => $impuls, 'fet' => $quan ); + } +} + +$nrm = count($menc_mat); +$imp_resp = null; + +// llegir fitxer per evitar repeticions +$impuls_arx = exec("cat ".$lloc."/fitxers/impulsos.txt", $eix_imp, $resp_imp); + +$eix_imp = implode(" ",$eix_imp); + +// verificar que un usuari fa més d'una volta la mateixa acció +$e = 0; +$nm = 0; +$num_seg = 0; +$mr = 0; +for ($e = 0; $e < $nrm; $e++) { + $m_id = $menc_mat[$e]['id']; + $miss_id = $menc_mat[$e]['mis_id']; + $usuari= $menc_mat[$e]['qui']; + $impuls_t= $menc_mat[$e]['impuls']; + $quan_m = $menc_mat[$e]['fet']; + $quan_str = strtotime($quan_m); + $impuls_arx = shell_exec("cat ".$lloc."/fitxers/impulsos.txt"); + $no_repetir = strpos($eix_imp,$m_id); + +// if ( ($impuls_t == "reblog") ) { + if (($impuls_t == "reblog")||($impuls_t == "favourite" )) { + $no_repetir = strpos($eix_imp, $m_id); + // escriu la menció al fitxer per no repetir-la + if($no_repetir === false) { + // per que siga només a partir de la data i hora de reinici + if($quan_str >= $temps_ini) { + $escriu_impulsos = fopen($lloc."/fitxers/impulsos.txt", "a") or die("No puc escriure al registre!"); + fwrite($escriu_impulsos, $m_id." ".$usuari." ".$impuls_t." ".$miss_id." ".$quan_m."\n"); + fclose($escriu_impulsos); + $log->lwrite("NOU IMPULS: ".$m_id." ".$usuari." ".$impuls_t." ".$miss_id." ".$quan_m.""); + $imp_mat[] = array ( 'id' => (int)$m_id, 'mis_id' => (int)$miss_id, 'qui' => $usuari, 'impuls' => $impuls_t, 'quan' => $quan_m ); + $nm++; + } + } + } +} +if($nm > 0) { + $log-> lwrite("He escrit ".$nm." ".(($nm<>1)?"registres":"registre")."."); + +// fer la matriu de les dades existents al json +//$usa_json = exec("php ".$lloc."/proves/proves_impulsos_json.php ".$lloc , $eix_usa_json, $resp_usa_json); +$usa_json = shell_exec("php ".$lloc."/proves/proves_impulsos_json.php ".$lloc); + + +// incloure les novetats a la matriu + + +/** +// actualitza el fitxer json +$fes_json = json_encode($json_dec, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_OBJECT_AS_ARRAY); +$escriu_f_json = fopen($lloc."/fitxers/impulsos.json", "w") or die("No puc escriure al registre!"); +fwrite($escriu_f_json, $fes_json); +fclose($escriu_f_json); +**/ +} +if( (filesize($lloc."/fitxers/impulsos.txt"))> (filesize($lloc."/fitxers/impulsos.bak")) ) { + $fil_seg = shell_exec("cat ".$lloc."/fitxers/impulsos.txt > ".$lloc."/fitxers/impulsos.bak"); +} + +$impp = 0; +$favp = 0; + +// aqui if de temps +if($temps_imp >= $espera_imp) { + + //recupera còpia de seguretat, si escau + if( (filesize($lloc."/fitxers/impulsos.txt")) == 0 ) { + $fil_seg = shell_exec("cat ".$lloc."/fitxers/impulsos.bak > ".$lloc."/fitxers/impulsos.txt"); + } + +// 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); + +// fer el gràfic amb les dades recopilades +$fer_grafic_imp = shell_exec($lloc."/utils/bot_plus_fergrafic_imp.php ".$lloc); + +// pujar gràfic + +// puja imatge a mastodont +$pub_cent = "."; +$pub_img = $lloc."/grafic/grafic_imp.png"; +$fitxer_tipus = mime_content_type($pub_img); + +$publica_img = array( + "file" => $pub_img, + "type"=> $fitxer_tipus, + "description" => 'Gràfic impulsos dels '.($nseg_ant).' seguidors.' + ); + +$publ_img = json_encode($publica_img); + + $status_data = array( + "status" => $pub_cent, + "text" => $pub_cent, + "language" => $llengua, + "visibility" => $visib_com + ); + +$pub_img = $lloc."/grafic/grafic_imp.png"; +$fitxer_tipus = mime_content_type($pub_img); +$fitxer_prep = curl_file_create($pub_img, $fitxer_tipus, 'file'); + +$publica_img = [ 'file' => $fitxer_prep, + 'description' => 'Gràfic impulsos dels '.($nseg_ant).' seguidors.', + 'text' => $pub_cent, + 'status' => 'missatge amb imatge des del bot' + ]; + +// pujada de la imatge +$ch_status = curl_init(); +curl_setopt($ch_status, CURLOPT_URL, $base_url . "/api/v2/media"); +curl_setopt($ch_status, CURLOPT_POST, 1); +curl_setopt($ch_status, CURLOPT_POSTFIELDS, $publica_img); +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); + +echo "\n\nresposta media : \n"; +print_r ($output_status); +$imat_mst = $output_status['id']; +$imat_url = $output_status['url']; + +// arreplegar dades imatge pujada +sleep(1); + + $bot_status = curl_init(); + curl_setopt($bot_status, CURLOPT_URL, $base_url . "/api/v1/media/".$imat_mst.""); + curl_setopt($bot_status, CURLOPT_RETURNTRANSFER, true); + curl_setopt($bot_status, CURLOPT_HTTPHEADER, $headers); + $resposta = (curl_exec($bot_status)); + $resposta_json = json_decode(curl_exec($bot_status)); + curl_close ($bot_status); +// var_dump($resposta); +// echo "resposta\n"; +// print_r($resposta); + $resposta = json_decode($resposta,true); +// echo "\n\nresposta json_decode\n"; +// print_r($resposta); + +echo "obtenció dades media: \n"; +print_r($resposta_json); +sleep(1); + +$im_id = $resposta['id']; +$im_url = $resposta['url']; +$im_type = $resposta['type']; +$im_desc = $resposta['description']; + +$img_bis = $lloc."/grafic/grafic_imp.png"; + +$imatge_adj = array('file' => $im_url, 'type' => $im_type, 'description' => $im_desc); +$imatge_adj_json = json_encode($imatge_adj); + +function http_build_query_for_curl( $arrays, &$new = array(), $prefix = null ) { + if ( is_object( $arrays ) ) { + $arrays = get_object_vars( $arrays ); + } + foreach ( $arrays AS $key => $value ) { + $k = isset( $prefix ) ? $prefix . '[' . $key . ']' : $key; + if ( is_array( $value ) OR is_object( $value ) ) { + http_build_query_for_curl( $value, $new, $k ); + } else { + $new[$k] = $value; + } + } +} + +//arsort($act_mat_ord); + + +// reblogs +//$impuls_resum = exec("cat ".$lloc."/fitxers/impulsos.txt | awk '{print $2}'", $eix_ir, $resp_ir ); +$impuls_resum = exec("cat ".$lloc."/fitxers/impulsos.txt | grep 'reblog' | awk '{print $2}'", $eix_ir, $resp_ir ); +$mat_reb = array_count_values($eix_ir); + +$a = 0; +arsort($mat_reb); +foreach ($mat_reb as $clau => $valor) { + $mat_reb_f[] = array('nom' => $clau, 'nombre' => $valor); + $a++; +} + +$us_imp = array_values($mat_reb_f)[0]['nom']; +$nu_imp = array_values($mat_reb_f)[0]['nombre']; + +// quants tenen els mateix nombre que el primer? +$acabaa = count($mat_reb_f); +for($i=0;$i<$acabaa;$i++) { + if($mat_reb_f[$i]['nombre'] == $nu_imp) { + $mat_reb_fp[] = array('article' => $clau, 'nombre' => $valor); + } +} +$tuts_imp_primers = count($mat_reb_fp); + +// favorits +$favorits_resum = exec("cat ".$lloc."/fitxers/impulsos.txt | grep 'favourite' | awk '{print $2}'", $eix_fr, $resp_fr ); +$mat_fav = array_count_values($eix_fr); + +$b = 0; +arsort($mat_fav); + +foreach ($mat_fav as $clau => $valor) { + $mat_fav_f[] = array('nom' => $clau, 'nombre' => $valor); +// echo "favorits: ".$clau."->".$valor."\n"; + $b++; +} + +$us_fav = array_values($mat_fav_f)[0]['nom']; +$nu_fav = array_values($mat_fav_f)[0]['nombre']; + +// quants tenen els mateix nombre que el primer? +$acabaf = count($mat_fav_f); +for($i=0;$i<$acabaf;$i++) { + if($mat_fav_f[$i]['nombre'] == $nu_fav) { + $mat_fav_fp[] = array('article' => $clau, 'nombre' => $valor); + } +} +$tuts_fav_primers = count($mat_fav_fp); + +//està activat missatges als usuaris? +if($act_impuls_usu == 1) { + +$nrmr = rand(2,3); + +// impulsos + for($f = 0; $f<$nrmr; $f++) { + $us_imp = array_values($mat_reb_f)[$f]['nom']; + $nu_imp = array_values($mat_reb_f)[$f]['nombre']; + $imp_resp = "Moltes gràcies @".$us_imp." per impulsar ".$nu_imp." ".(($nu_imp<>1)?"publicacions":"publicació")." des del ".date('d/m/Y', $temps_ini).". 👏 \n#SocUnBot 🤖 \n".$bot_nom." ".$bot_versio.""; + $log -> lwrite ($imp_resp); + + // publicar + + $imp_dades = array( + "status" => $imp_resp, + "language" => $llengua, + "visibility" => $visib_imp_usu + ); + + PublicaMissatge($base_url,$headers,$imp_dades); + + $impp++; + } + +// favorits + for($g = 0; $g<$nrmr; $g++) { + $us_fav = array_values($mat_fav_f)[$g]['nom']; + $nu_fav = array_values($mat_fav_f)[$g]['nombre']; + $fav_resp = "Moltes gràcies @".$us_fav." per fer favorit a ".$nu_fav." ".(($nu_fav<>1)?"publicacions":"publicació")." des del ".date('d/m/Y', $temps_ini).". 👏 \n#SocUnBot 🤖 \n".$bot_nom." ".$bot_versio.""; + $log -> lwrite ($fav_resp); + + // publicar + + $fav_dades = array( + "status" => $fav_resp, + "language" => $llengua, + "visibility" => $visib_imp_usu + ); + + PublicaMissatge($base_url,$headers,$imp_dades); + + $favp++; + } + +//final activació missatges impulsos i favorits als usuaris +} + +// reblog +//$public_resum = shell_exec("cat ".$lloc."/fitxers/impulsos.txt | awk '{print $4}'" ); +$public_resum = shell_exec("cat ".$lloc."/fitxers/impulsos.txt | grep 'reblog' | awk '{print $4}'" ); +$pub_resum = explode("\n",$public_resum); + +$mat_res = array_count_values($pub_resum); + +$c = 0; +arsort($mat_res); +foreach ($mat_res as $clau => $valor) { + echo "$clau = $valor\n"; + $mat_res_f[] = array('article' => $clau, 'nombre' => $valor); + $c++; +} + +$mes_comp_id = array_values($mat_res_f)[0]['article']; +$mes_comp_vl = array_values($mat_res_f)[0]['nombre']; + +// favorits +$public_resum_f = shell_exec("cat ".$lloc."/fitxers/impulsos.txt | grep 'favourite' | awk '{print $4}'" ); +$pub_resum_f = explode("\n",$public_resum_f); + +$mat_res_f = array_count_values($pub_resum_f); + +$d = 0; +arsort($mat_res_f); +foreach ($mat_res_f as $clau => $valor) { +// echo "favorits_resum: ". $clau. "=". $valor."\n"; + $mat_res_fa[] = array('article' => $clau, 'nombre' => $valor); + $d++; +} + +$mes_fav_id = array_values($mat_res_fa)[0]['article']; +$mes_fav_vl = array_values($mat_res_fa)[0]['nombre']; + +// 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); + +if($tuts_imp_primers == 1) { +$comp_miss = "Este és el tut ⬆️ que mes heu compartit, ".$mes_comp_vl." ".(($mes_comp_vl<>1)?"voltes":"volta").", des del ".date('d/m/Y',$temps_ini).".\n". +"Moltes gràcies!\n\n". +"Estadístiques 📈 \n". +"Tuts favorits -> ".$d." tuts\n". +"Els han marcat -> ".$b." persones.\n". +"🎖️ Qui més favorits n'ha fet ".$nu_fav."\n". +"El tut que més n'ha rebut ".$mes_fav_vl."\n". +"Ha participat un ".round( (($b/$nseg_ant)*100), 2 )."% sobre el total dels seguidors.\n". +"Tuts impulsats -> ".$c." tuts\n". +"Els han impulsat -> ".$a." persones.\n". +"🥇 Qui més ha impulsat n'ha fet ".$nu_imp." impulsos.\n". +"Ha participat un ".round( (($a/$nseg_ant)*100), 2 )."% sobre el total dels seguidors.\n". + +"#ResumSetmanal #SocUnBot \n".$bot_nom." v".$bot_versio.""; +} else { +$comp_miss = "Este és un dels ".$tuts_imp_primers ." tuts ⬆️ que mes heu compartit, ".$mes_comp_vl." ".(($mes_comp_vl<>1)?"voltes":"volta").", des del ".date('d/m/Y',$temps_ini).".\n". +"Moltes gràcies!\n\n". +"Estadístiques 📈 \n". +"Tuts favorits -> ".$d." tuts\n". +"Els han marcat -> ".$b." persones.\n". +"🎖️ Qui més favorits n'ha fet ".$nu_fav."\n". +"El tut que més n'ha rebut ".$mes_fav_vl."\n". +"Ha participat un ".round( (($b/$nseg_ant)*100), 2 )."% sobre el total dels seguidors.\n". +"Tuts impulsats -> ".$c." tuts\n". +"Els han impulsat -> ".$a." persones.\n". +"🥇 Qui més ha impulsat n'ha fet ".$nu_imp." impulsos.\n". +"Ha participat un ".round( (($a/$nseg_ant)*100), 2 )."% sobre el total dels seguidors.\n". + +"#ResumSetmanal #SocUnBot \n".$bot_nom." v".$bot_versio.""; +} + +$tut = $comp_miss; + +$log -> lwrite($comp_miss); + +if($act_impuls_resum == 1) { + + $status_data2 = array( + "status" => $tut, + "language" => $llengua, + "visibility" => $visib_com + ); + +$tut_matriu = array( + "status" => $tut, + "text" => $tut, + "language" => $llengua, + "media_ids[]" => $im_id, + "visibility" => $visib_cent, + "sensitive" => null, + "spoiler_text" => null, + "in_reply_to_id" => $mes_comp_id +); + +http_build_query_for_curl( $tut_matriu, $tut_dades ); + +// PublicaMissatge($headers,$base_url,$tut_dades); + $pub_text_imat = curl_init(); + curl_setopt($pub_text_imat, CURLOPT_URL, $base_url . "/api/v1/statuses"); + curl_setopt($pub_text_imat, CURLOPT_POST, 1); + curl_setopt($pub_text_imat, CURLOPT_POSTFIELDS, $tut_dades); + curl_setopt($pub_text_imat, CURLOPT_RETURNTRANSFER, true); + curl_setopt($pub_text_imat, CURLOPT_HTTPHEADER, $headers); + $resposta_img_txt = json_decode(curl_exec($pub_text_imat),true); + curl_close ($pub_text_imat); + + +//exit; + $mr++; + + // executa activitat dels seguidors + $activitat_seguidors = shell_exec("/usr/bin/php -f ".$lloc."/proves/proves_activitat_seguidors.php ".$lloc.""); + + // final si estadistiques està encés + } +// final if per publicar (caldrà descomentar-lo) +} +else { + +$temps_cal = ($espera_imp - $temps_imp); + + if( ($nm > 0) && (($espera_imp - $temps_imp)>= 86400) ) { + $log -> lwrite("Manquen per publicar ".gmdate("d",$temps_cal)." dies i ".gmdate("H:i:s",$temps_cal)." hores"); + } + if(($espera_imp - $temps_imp)<= 86400) { + $log->lwrite("".( gmdate("d",$temps_cal)<>1 ? "Manquen ".gmdate('d',$temps_cal)." dies i ".gmdate('H:i:s',$temps_cal)." hores.":"No manca cap dia i ".gmdate('H:i:s',$temps_cal)." hores.").""); + } +} + +//echo "propera publicació: ".$espera_imp." | ".date('r',$espera_imp)."\n"; + +// condició publicar per refer el fitxer de temps +if( ($impp >= 1)||($mr==1)||($favp >=1) ) { +//reinicie el fitxer una volta publique el missatge + +$buida_imp = shell_exec(": > ".$lloc."/fitxers/impulsos.txt"); +$buida_imp_cp = shell_exec(": > ".$lloc."/fitxers/impulsos.bak"); +$buida_json = file_put_contents($lloc."/fitxers/impulsos.json", json_encode([])); + +// crea el fitxer per fer el compte de temps +$data_ara = strtotime("now"); +$data_conv = strtotime("1 week"); +$data_dif = $data_ara - $data_conv; +$data_cal = $data_ara + $data_dif; +$data_conv = ($data_conv + rand(-300,300)); + +// escriu el fitxer per saber quan publicar +$escriu_imp_t = fopen($lloc."/fitxers/impulsos_temps.txt", "w") or die("No puc escriure al registre!"); +fwrite($escriu_imp_t, $data_conv); +fclose($escriu_imp_t); +} + +$tcf = microtime(true); +$dc = $tcf - $tc; +$log->lwrite("Temps impulsos: ".round($dc,4).""); +?> diff --git a/utils/bot_plus_mencions.php b/utils/bot_plus_mencions.php new file mode 100644 index 0000000..a45e954 --- /dev/null +++ b/utils/bot_plus_mencions.php @@ -0,0 +1,209 @@ +lfile(''.$log_fitxer.''); + +$log->lwrite("Estàn activades les respostes a les mencions."); + +// preparatius i variables comunes +$resposta = ConsultaNotificacions($token,$base_url,$limit_m,$headers); + +$tmc = microtime(true); +$dcon = $tmc - $tm; + +$nr = count($resposta); + +$menc_mat = array(); +$d = 0; +for ($d = 0; $d < $nr; $d++) { +// triar les variables que volem de la matriu + $men_id = $resposta[$d]['id']; + $mencio = $resposta[$d]['type']; + $men_tp = $resposta[$d]['created_at']; + $usu_id = $resposta[$d]['account']['id']; + $usu_ac = $resposta[$d]['account']['acct']; +// $usu_no = $resposta[$d]['account']['username']; +// $usu_dp = $resposta[$d]['account']['display_name']; + if ($mencio == "mention") { + $mis_id = $resposta[$d]['status']['id']; + } else { $mis_id = 0; } + $menc_mat[] = array ( 'id' => (int)$men_id, 'mis_id' => (int)$mis_id, 'qui' => $usu_ac, 'mencio' => $mencio, 'quan' => $men_tp ); +// } +// echo "tipus de menció ".$d.": ".$mencio." i nº ".$men_id." - qui: ".$qui."\n"; +// sleep(1); +} + +$nombre_matriu = count($menc_mat); +$men_resp = null; + +//if($nombre_matriu >= 1) { + +// llegir fitxer per evitar repeticions +$mencio_arx = shell_exec("cat ".$lloc."/fitxers/mencions_r.txt"); + +// verificar que un usuari fa més d'una volta la mateixa acció (?); +$e = 0; +$nm = 0; +$num_seg = 0; +$mr = 0; +for ($e = 0; $e < $nombre_matriu; $e++) { + $m_id = $menc_mat[$e]['id']; + $miss_id = $menc_mat[$e]['mis_id']; + $usuari= $menc_mat[$e]['qui']; + $mencio_t= $menc_mat[$e]['mencio']; + $temps = $menc_mat[$e]['quan']; + $mencio_arx = shell_exec("cat ".$lloc."/fitxers/mencions_r.txt"); + $no_repetir = strpos($mencio_arx,$miss_id); + if ($mencio_t == "mention") { +// if ( ($mencio_t == "mention") && ($mis_id <>0)) { + $no_repetir = strpos($mencio_arx,$miss_id); +// echo "no repetir: ".$e."|".$usuari."|".$no_repetir."\n"; +// $log->lwrite("no repetir: ".$e."|".$usuari."|".$no_repetir.""); +// sleep(2); + if( ($no_repetir === false) ) { +// echo "menció de : ".$usuari." - ".$mencio_t." - ".$miss_id."\n"; + if (is_int($miss_id/7)) { + $men_resp = "Ja em disculparàs, @".$usuari." soc un bot :cli_user: amb la versió ".$bot_versio." i encara no converse. \nDe tota manera, moltes gràcies per la teua menció.\n🤖 #SocUnBot"; + } elseif (is_int($miss_id/5)) { + $men_resp = "Moltes gràcies per la menció, @".$usuari.".:cli_user:\n Soc ".$bot_nom." v".$bot_versio." :cli_user:\n🤖 #SocUnBot"; + } elseif (is_int($miss_id/3)) { + $men_resp = "He vist que m'has mencionat, @".$usuari." i et done les gràcies.:cli_user:\n Soc ".$bot_nom." v".$bot_versio." :cli_user:\n🤖 #SocUnBot"; + } elseif (is_int($miss_id/2)) { + $men_resp = "Agraït per la menció, @".$usuari.".:cli_user:\n Soc ".$bot_nom." v".$bot_versio." :cli_user:\n🤖 #SocUnBot"; + } else { + $men_resp = "Gràcies per mencionar-me, @".$usuari.". Soc ".$bot_nom." i la meua versió és ".$bot_versio." :cli_user:.\n🤖 #SocUnBot"; + } + $en_resposta = $miss_id; + + if ( ($men_resp != null) ) { + if($act_mencio_resp == 1) { + + // Publica a Mastodon + $dades_tut = array( + "status" => $men_resp, + "language" => $llengua, + "visibility" => $visib_mencs, + "in_reply_to_id" => $en_resposta + ); + + //print_r($status_data); + //sleep(10); + PublicaMissatge($headers,$base_url,$dades_tut); + $log->lwrite("NOVA MENCIO: ".$men_resp." : ".$usuari." - id: ".$en_resposta." "); + + } + + $decisio = TriaOpcio($en_resposta); + + if( ($decisio == 1) || + ($decisio == 2) || + ($decisio == 3) || + ($decisio == 4) || + ($decisio == 5) || + ($decisio == 8) || + ($decisio == 9) ) { + //if(is_int($en_resposta/2)) { + FesRebloc($base_url,$en_resposta,$headers); + $heoptat = "he fet impuls"; + //print_r($fav_output_status); + } elseif( ($decisio == 6) || + ($decisio == 7) || + ($decisio == 10) ) { + FesFavorit($base_url,$en_resposta,$headers); + $heoptat = "he fet favorit"; + } else { + FesFavorit($base_url,$en_resposta,$headers); + FesRebloc($base_url,$en_resposta,$headers); + $heoptat = "he fet impuls i favorit"; + //print_r($reb_output_status); + } + + // escriu la menció al fitxer per no repetir-la + $escriu_mencions = fopen($lloc."/fitxers/mencions_r.txt", "a") or die("No puc escriure al registre!"); + fwrite($escriu_mencions, $en_resposta."\n"); + fclose($escriu_mencions); + //echo "".$men_resp." - id: ".$en_resposta." "; + $escriu_mencions_detall = fopen($lloc."/fitxers/mencions.txt", "a") or die("No puc escriure al registre!"); + fwrite($escriu_mencions_detall, $m_id."-".$en_resposta."-".$usuari."-".$mencio_t."-".$temps."\n"); + fclose($escriu_mencions_detall); +// echo "He escrit ". $m_id."-".$en_resposta."-".$usu_ac."-".$temps."\n"; + $mr++; + + } + $menc_mat_f[] = array( 'id' => (int)$m_id, 'mis_id' => (int)$miss_id, 'qui' => $usuari, 'mencio' => $mencio_t, 'quan' => $temps ); + + $nm++; +// echo "nm: ".$nm."\n"; + $log->lwrite("NOVA MENCIO: ".$usuari." - id: ".$en_resposta." ".$mencio_t." ".$heoptat); + + // final missatge no es nul + } + + //final no repetir + } + +// final bucle for +} +/** +if($nm>=1) { + $fes_json = json_encode($menc_mat_f, JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES|JSON_OBJECT_AS_ARRAY); + $escriu_f_json = fopen($lloc."/fitxers/mencions.json", "a") or die("No puc escriure al registre!"); + fwrite($escriu_f_json, $fes_json); + fclose($escriu_f_json); +} +**/ +// $menc_json_actual = shell_exec("php /proves/proves_mencions_json.php."); + +//print_r($output_status); +//} +//echo $nm."\n"; + +//final if publicat +// } + +// final condicional per estalviar temps(?) +//} + +//$impuls = shell_exec("php ".$lloc."/proves/proves_mencions_json.php ".$lloc); + +// fer la matriu de les dades existents al json +if ($nm > 0) { +//$usa_json = exec("php ".$lloc."/proves/proves_impulsos_json.php ".$lloc , $eix_usa_json, $resp_usa_json); +$usa_json = shell_exec("php ".$lloc."/proves/proves_mencions_json.php ".$lloc); +} + +//retalle a un màxim de 40 linies +$fit_mencions = $lloc."/fitxers/mencions_r.txt"; +$lin_men = count(file($fit_mencions)); +if($lin_men > 60) { + $net_men0 = shell_exec("tail -60 ".$lloc."/fitxers/mencions_r.txt | tee ".$lloc."/fitxers/mencions_r.txt"); + $net_men1 = shell_exec("tail -60 ".$lloc."/fitxers/mencions.txt | tee ".$lloc."/fitxers/mencions.txt"); +} + +$tmf = microtime(true); +$dm = $tmf - $tm; +//echo "Temps mencions: ".round($dm,4).""; +$log->lwrite("Temps mencions: ".round($dm,4).""); + + +// afegir aqui i arrancar els impulsos? + + + + +?>