Skip to content

Commit

Permalink
Correcion de la ejecucion de precios
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew0914 committed Nov 18, 2017
1 parent 73f9749 commit e770aab
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 27 deletions.
44 changes: 23 additions & 21 deletions js/scraping-precios.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@

var respiro = 3000;
var respiro = 3000;
var inicio = 0;
var fin = 0;
var cuantosProductos = 0;
var totalIntervalos = 0;
var indice = 0;
var intervalos=null;

function printConsola(texto){
var previo = "";
if($("#consola_scrapping").html()){
Expand Down Expand Up @@ -77,35 +78,30 @@ function getCuantosByCategoria(){
}

function getIntervalos(){
var intervalos = new Array();
fin = 35;
var intervalosObtenidos = new Array();
fin = 50;
var intervalo = null;

while(fin <= cuantosProductos){
intervalo = {"inicio" : inicio , "fin" : fin};
intervalos.push(intervalo);
inicio = fin;
fin = fin + 35 ;
}

if(fin > cuantosProductos){
fin = fin -35;
}
while(inicio < cuantosProductos){
if((cuantosProductos - inicio) < 50){
var ultimo = cuantosProductos - inicio;
intervalo = {"inicio" : inicio , "fin" : ultimo};
intervalosObtenidos.push(intervalo);
break;
}else{
intervalo = {"inicio" : inicio , "fin" : fin};
intervalosObtenidos.push(intervalo);
inicio+= 50 ;
}

if(fin < cuantosProductos){
intervalo = {"inicio" : fin , "fin" : cuantosProductos};
intervalos.push(intervalo);
}

return intervalos;

return intervalosObtenidos;
}


function getPrecios(){
$("#segundo_scrap").html("Ejecutando scraping en precios " + "<img src='img/loading.gif' width='40' height='40'><br><br>");
var intervalos = getIntervalos();
totalIntervalos = intervalos.length - 1;
var categoria = $("#categoria").val();
var tienda = $("#tiendas").val();
var datos = 'prueba=precios' + '&inicio='+ intervalos[indice].inicio + '&fin='+ intervalos[indice].fin + '&categoria=' + categoria + "&shop="+tienda;
Expand Down Expand Up @@ -133,6 +129,7 @@ function getPrecios(){
indice = 0;
inicio = 0;
fin = 0;
intervalos = null;
}
}

Expand Down Expand Up @@ -174,6 +171,11 @@ function getCategorias(){
});
}

function setIntervalos(){
intervalos = getIntervalos();
totalIntervalos = intervalos.length - 1;
}

$(document).ready(function() {
getCategorias();
});
8 changes: 4 additions & 4 deletions js/scrapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,25 @@ function getCuantosByCategoria(){

function getIntervalos(){

var intervalos = new Array();
var intervalosObtenidos = new Array();
fin = 50;
var intervalo = null;

while(inicio < cuantosProductos){
if((cuantosProductos - inicio) < 50){
var ultimo = cuantosProductos - inicio;
intervalo = {"inicio" : inicio , "fin" : ultimo};
intervalos.push(intervalo);
intervalosObtenidos.push(intervalo);
break;
}else{
intervalo = {"inicio" : inicio , "fin" : fin};
intervalos.push(intervalo);
intervalosObtenidos.push(intervalo);
inicio+= 50 ;
}

}

return intervalos;
return intervalosObtenidos;

}

Expand Down
4 changes: 2 additions & 2 deletions scrapng-precios.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@
<br><br>
</li>
<li id="segundo_scrap" style="display: none;">
<button class="btn btn-success" onclick="getPrecios();">
Actualizar precio de productos
<button class="btn btn-success" onclick="setIntervalos();getPrecios();">
Obtener precio de productos
</button>
<br><br>
</li>
Expand Down

0 comments on commit e770aab

Please sign in to comment.