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/xxxxxxxxxx"); 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 = $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"; ?>