php-pinterest-bot icon indicating copy to clipboard operation
php-pinterest-bot copied to clipboard

Add recommended searches

Open seregazhuk opened this issue 7 years ago • 1 comments

**Request URL:**https://www.pinterest.de/resource/SearchGuidesResource/get/ data:{"options":{"query":"test"},"context":{}}

seregazhuk avatar Aug 08 '17 20:08 seregazhuk

I want to thank you for such a great library, it helps a lot!

  1. The first question about the search: If you specify an unknown word for Pinterest, then it will not have pins for such a request, but the result will not be completely correct (http://prntscr.com/lfh9gt). Is there any way to return an empty array or NULL?

  2. The second question is regarding search speed: For example, I want to get a lot of pins for the keyword "cat". I need to get no less than 2000 pins ... When you do pagination, 0-50, 50-100, 100-150 etc., then after receiving more than 300 pins, the rate at which pins are received slows down. the script always starts to work from the first pin, and until it receives all 300 posts, he will not be able to give me the new results ...

$counter = 0;
$array_pins = array();
$times = array();

do{
	$tmp_array_pins = array();

	$time_start = microtime(true);
	$tmp_array_pins = iterator_to_array($bot->pins->search($_REQUEST['keywords'])->take(50)->skip($counter)->get());
	$time_end = microtime(true);
	
	$times["$counter - ".($counter+50)] = $time_end - $time_start;
	
	$array_pins = array_merge($array_pins, $tmp_array_pins);
	$counter = count($array_pins);

}while(count($tmp_array_pins)>0 && count($array_pins) <= 500);


print_r($times);

//result
//Array
//(
//    [0 - 50] => 3.0791759490967
//    [50 - 100] => 4.5662610530853
//    [100 - 150] => 6.446368932724
//    [150 - 200] => 8.486485004425
//    [200 - 250] => 13.37276506424
//    [250 - 300] => 12.959740877151
//    [300 - 350] => 15.391880989075
//    [350 - 400] => 18.289046049118
//    [400 - 450] => 20.838191986084
//    [450 - 500] => 21.903252124786
//    [500 - 550] => 26.088492870331
//)

Is it possible to speed up the script?

Let me know if I need provide more details

panchenkoprog avatar Nov 07 '18 18:11 panchenkoprog