Viewing file: bajar_libros_semana_nuevo_consola.php (11.79 KB) -rw-rw-r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
// hasta 28758, fecha 14/09/2013
//si no existe ps-lef |grep php-fpm, podr�amos parchearlo con el comando /usr/local/nginx/sbin/nginx -s reload include "../frames/classes/dZip.inc.php"; include "../frames/conn.php";
if ($argv[2]){ $libro_inicio=$argv[1]; $libro_final=$argv[2];
$nombre=$argv[3]; $directorio="../libros/";
$counter=0;
$sql=" SELECT libros.id ,libros.titulo,libros.autor,libros.genero,libros.subgenero,libros.programa, libros.anyo,libros.ruta,libros.inftp,libros.tamano, sinopsis.sinopsis, sinopsis.imagename FROM libros LEFT OUTER JOIN sinopsis ON libros.id = sinopsis.id_book WHERE (libros.id >=$libro_inicio and libros.id <=$libro_final) and (libros.inftp=1 and libros.tamano>0) order by libros.id asc "; echo $sql;
// $fecha=NEW DateTime(date("$libro_final 23:59:00")); // $fecha->modify("-1 day");
// print_r($fecha);
/*$sql="select t1.id,t1.titulo,t1.autor,t1.genero, t1.subgenero,t1.programa,t1.anyo,t1.ruta, t2.id_book, t2.imagename,t2.sinopsis from libros as t1, sinopsis as t2 where fecha_subida >='". $libro_inicial ."' and fecha_subida <='". $libro_final ."' and (inftp=1 or inftp=9) and t2.imagename like '%.jpg'". " and t1.id=t2.id_book ". " and tamano>0 ". "$anadido order by id asc"; echo $sql."\n"; */
$res=mysql_query($sql,$conn); echo mysql_error(); $counter++; echo "creando directorio "; echo $destino=trim($libro_inicio)."----".trim($libro_final)."\n"; // mkdir($destino,0777);
echo "fichero en www.papyrefb2.net/automatas/recopilatorios_semanales_nuevos/recopilacion_desde_".trim($libro_inicio)."_al_".trim($libro_final).".zip \n"; // $zip = new dZip("./recopilatorios_semanales_nuevos/recopilacion_desde_".trim($libro_inicial)."_al_".trim($libro_final).".zip"); $zip = new dZip("./recopilatorios_semanales_nuevos/$nombre.zip"); $zip_portadas=new dZip("./recopilatorios_semanales_nuevos/portadas_".trim($libro_inicio)."_al_".trim($libro_final).".zip"); $ccadena=" <center><h1>Recopilaci�n de libros en pr�stamo de <b>www.papyrefb2.net</b>, desde ".trim($libro_inicio) ." hasta ".trim($libro_final)."</h1><br><br> <table border=1 ><tr><td bgcolor=#CAEFF7>Numero<td bgcolor=#CAEFF7>T�tulo<td bgcolor=#CAEFF7>autor<td bgcolor=#CAEFF7>fichero</tr>"; $texto=""; $sepa=chr(10).chr(13); $handlesip=fopen("./recopilatorios_semanales_nuevos/".trim($libro_final).".txt","w+"); $handleisbn=fopen("./recopilatorios_semanales_nuevos/isbn.txt","w+"); $registro_inicial=0; while ($row=mysql_fetch_array($res)){ if ($registro_inicial==0)$registro_inicial=$row['id']; if (counter/2==intval($counter/2)){ $color="#F0F0F0"; }else{ $color="#FFFFC0"; } if (strstr($row['ruta'],"/libros/")){ $vard=split('/libros/', $row['ruta']); $prefix="../libros/"; }else{ $vard=split('/newlibros/', $row['ruta']); $prefix="../newlibros/"; }
$titulo=trim($vard[1]); echo "el titulo es "; echo $titulo."<br>";
$ccadena.="<tr><td bgcolor=$color>{$row['id']}<td bgcolor=$color>{$row['titulo']}<td bgcolor=$color>{$row['autor']}<td bgcolor=$color>$titulo</tr>"; $cctxt.=$row['id']."-".$row['titulo']."-".$row['autor']."<br>"; @$zip->addFile($prefix.$titulo,"$titulo"); //@$zip->addFile("../newlibros/$titulo","$titulo"); $zip_portadas->addfile("../includes/{$row['imagename']}",$row['imagename']); echo "../includes/{$row['imagename']} ".$row['imagename']; if (strtoupper($_REQUEST['total'])<>'SI'){ $texto="##1##".$row['id']; fwrite($handlesip, $texto); $texto="##2##".$row['autor']; fwrite($handlesip, $texto); $texto="##3##".$row['titulo']; fwrite($handlesip, $texto); $texto="##4##".$row['genero']; fwrite($handlesip, $texto); $texto="##5##".$row['subgenero']; fwrite($handlesip, $texto); $texto="##6##".$row['anyo']; fwrite($handlesip, $texto); $texto="##7##".$row['programa']; fwrite($handlesip, $texto); $texto="##8##".$row['sinopsis']."$$$$"; fwrite($handlesip, $texto); }
$registro_final=$row['id']; }
echo "<pre>";
$zip_portadas->save(); echo $ccadena.="</table>"; echo "<br><b>seguimos para bingo!</b>";
$handle=fopen("./recopilatorios_semanales_nuevos/Lista_de_libros_y_autores.html","w+"); fwrite($handle, $ccadena); fclose($handle);
if (strtoupper($_REQUEST['total'])<>'SI' or 1==1){ echo "<br><b>requesto NO es si</b>";
}else{ echo "<br><b>requesto SI es si</b>"; $sql=" SELECT libros.id ,libros.titulo,libros.autor,libros.genero,libros.subgenero,libros.programa, libros.anyo,libros.ruta,libros.inftp,libros.tamano, sinopsis.sinopsis, sinopsis.imagename FROM libros LEFT OUTER JOIN sinopsis ON libros.id = sinopsis.id_book WHERE libros.inftp=1 and libros.tamano>0 and (libros.id >=$libro_inicio and libros.id <=$libro_final) order by libros.id asc "; echo "<br>".$sql."<$br>"; echo $rex=mysql_query($sql,$conn); echo $texto; while($rowx=mysql_fetch_array($rex)){ $texto="##1##".$rowx['id']; fwrite($handlesip, $texto); $texto="##2##".$rowx['autor']; fwrite($handlesip, $texto); $texto="##3##".$rowx['titulo']; fwrite($handlesip, $texto); $texto="##4##".$rowx['genero']; fwrite($handlesip, $texto); $texto="##5##".$rowx['subgenero']; fwrite($handlesip, $texto); $texto="##6##".$rowx['anyo']; fwrite($handlesip, $texto); $texto="##7##".$rowx['programa']; fwrite($handlesip, $texto); $texto="##8##".$rowx['sinopsis']."$$$$"; fwrite($handlesip, $texto);
} } echo $handlesip; fclose($handlesip);
// aqui, añadimos los borrados desde el recopilatorio gigante mayor que 5430 $handleborrar=fopen("./recopilatorios_semanales_nuevos/descartados_".trim($libro_final).".txt","w+"); if (!$handleborrar)die("error en handleborrar"); $sql2="SELECT id FROM libros WHERE inftp<>1 and (libros.id <=$libro_final) "; $ser=mysql_query($sql2,$conn); echo mysql_error(); while ($rowborrar=mysql_fetch_array($ser)){ fwrite ($handleborrar,$rowborrar['id'].chr(10).chr(13)); } fclose($handleborrar); // aqui a�adimos las puntuaciones $handleborrar=fopen("./recopilatorios_semanales_nuevos/valoraciones.txt","w+"); if (!$handleborrar)die("error en handleborrar"); $sql2="SELECT t1.id as id,t2.id as id2,t2.inftp,t1.total_votes,t1.total_value FROM ratings as t1,libros as t2 WHERE t1.id=t2.id and t2.inftp=1 and t2.id <= $registro_final order by t1.id"; $ser=mysql_query($sql2,$conn); echo mysql_error(); while ($rowborrar=mysql_fetch_array($ser)){ $nota= number_format($rowborrar['total_value']/$rowborrar['total_votes'], 2, '.', ''); //echo $rowborrar['id']."-".$rowborrar['total_value']."/".$rowborrar['total_votes']."------".$rowborrar['total_value']/$rowborrar['total_votes']."----$nota<br>"; fwrite ($handleborrar,"##".$rowborrar['id']."##$nota##".$rowborrar['total_votes']."##".chr(10).chr(13)); } fclose($handleborrar); // aqui ir�a el isbn
$sql3="select * from isbn where 1"; $ser3=mysql_query($sql3,$conn); while($rowisbn=mysql_fetch_array($ser3)){
fwrite($handleisbn,"##{$rowisbn['id_book']}##"); if ($rowisbn['isbn']){ fwrite($handleisbn,"{$rowisbn['isbn']}##"); }else{ fwrite($handleisbn,"-##"); } if ($rowisbn['editorial']){ fwrite($handleisbn,"{$rowisbn['editorial']}##".chr(10).chr(13)); }else{ fwrite($handleisbn,"-##".chr(10).chr(13)); } } fclose($handleisbn); $zip->addFile("./recopilatorios_semanales_nuevos/Lista_de_libros_y_autores.html","Lista_de_libros_y_autores.html"); $zip->addFile("./recopilatorios_semanales_nuevos/portadas_".trim($libro_inicial)."_al_".trim($libro_final).".zip","portadas_".trim($libro_inicial)."_al_".trim($libro_final).".zip"); $zip->addFile("./recopilatorios_semanales_nuevos/".trim($libro_final).".txt",trim($libro_final).".txt"); $zip->addFile("./recopilatorios_semanales_nuevos/descartados_".trim($libro_final).".txt","descartados_".trim($libro_final).".txt"); $zip->addFile("./recopilatorios_semanales_nuevos/valoraciones.txt","valoraciones.txt"); echo "<pre>";
$zip->addFile("./recopilatorios_semanales_nuevos/isbn.txt","isbn.txt"); echo "<pre>";
//print_r($zip); if (!$_REQUEST['nozip']){ $zip->save(); }
// subimos a hostmonster
if ($_REQUEST['ftp']=='si'){ $ftp_server = "ftp.fichfilkraft.com"; // add server name $ftp_user_name = "fichfilk"; // add user name $ftp_user_pass = "15xj3Gm5Fo"; // add password $dst_dir = "/www/5652164542316554/files/"; // add destination directory ( www/upload/ ) $archivo_origen="recopilacion_desde_".trim($libro_inicial)."_al_".trim($libro_final).".zip"; $ftp= new ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir); $ftp->delete($archivo_origen); $ftp->ls(); echo "<pre>"; print_r($ftp); $directorio_origen="./recopilatorios_semanales_nuevos/"; echo "subiendo $archivo_origen"; $ftp->sendfile($archivo_origen,$directorio_origen.$archivo_origen); $ftp->ls(); echo "<br>--------------------------fin----------------------<br>"; print_r($ftp); } echo "<br>".$cctxt;
}
class ftp { public $ftp_server; public $ftp_user_name; public $ftp_user_pass; public $dst_dir; public $conn_id; public $login_result; public $mi_error; public $error=false; public $listadirectorio; function ftp($ftp_server,$ftp_user_name,$ftp_user_pass,$dst_dir) { if ($ftp_server!="" && $ftp_user_name!="" && $ftp_user_pass!="" && $dst_dir!="") { $this->ftp_server = $ftp_server; $this->ftp_user_name = $ftp_user_name; $this->ftp_user_pass = $ftp_user_pass; $this->dst_dir = $dst_dir; } else return false; // bad parametrs if (!$this->connect()){ echo "bad connect"; return false; } if (!$this->setdir()){ echo "no exist directory "; return false; } return true; // ALL OK }
/* FTP connect */ function connect() { $this->conn_id = ftp_connect($this->ftp_server); $this->login_result = ftp_login($this->conn_id, $this->ftp_user_name, $this->ftp_user_pass); if ((!$this->conn_id) || (!$this->login_result)) return false; else return true; } function disconnect() { return(ftp_close($this->conn_id)); }
/* Set Directory */ function setdir() { if (!ftp_chdir($this->conn_id, $this->dst_dir)){ $this->mi_error="no se pudo cambiar el directorio"; $this->error=true; return false; }else{ // echo ftp_pwd($this->conn_id); return true; } }
/* Send file */ /* INPUT: $remote_file -> file for send $file -> read file $mode -> "FTP_BINARY","FTP_ASCII",... */ function sendfile($remote_file, $file, $mode="FTP_BINARY") { if (!ftp_put($this->conn_id, $remote_file, $file, FTP_BINARY)){ $this->mi_error="no se pudo subir {$remote_file} {$file}"; $this->error=true; return false; }else{ return true; } } function getfile($local_file,$remote_file,$mode="FTP_BINARY") { $this->error=false; if (!ftp_get($this->conn_id, $local_file, $remote_file, FTP_BINARY)){ $this->mi_error="no se pudo bajar {$remote_file} {$file}"; $this->error=true; return false; }else{ $this->error=false; return true; } } function delete($file) { if (!ftp_delete($this->conn_id, $file)) { $this->mi_error="no se pudo borrar {$file}"; $this->error=true; return false; }else{ return true; }
} function ls() { $this->listadirectorio=ftp_nlist($this->conn_id, ftp_pwd($this->conn_id)); } function rename($oldname, $newname) { if (!ftp_rename($this->conn_id, $oldname, $newname) ){ $this->mi_error="no se pudo cambiar el nombre {$oldname} al nuevo: {$newname}"; $this->error=true; return false; }else{ return true; } }
} //end class ?>
|