fixing API Problems when to many results

This commit is contained in:
schrom01
2023-09-26 17:30:35 +02:00
parent 8bd927dd23
commit 6ec770f27c
4 changed files with 32 additions and 14 deletions
+17 -4
View File
@@ -4,7 +4,7 @@ include "read_write_xlsx.php";
include "emailSender.php";
$maxExecutionTime = 480;
$maxExecutionTime = 300;
$taskDir = 'tasks';
$downloadDir = 'download';
$minTaskOldness = 10;
@@ -18,7 +18,11 @@ if(!is_dir($downloadDir)){
function doRequest($data, $filename, $username, $password)
{
$response = sendAPICompanySearchRequest($username, $password, $data);
$companyArray = json_decode($response, true);
$responseObject = json_decode($response, true);
if(array_key_exists("error", $responseObject)) {
return false;
}
$companyArray = $responseObject['list'];
$companyData = array();
foreach ($companyArray as $company) {
$companyFullData = json_decode(sendAPICompanyInfoRequest($username, $password, $company['uid']), true)[0];
@@ -40,6 +44,11 @@ function doRequest($data, $filename, $username, $password)
}
fclose($file);
}
if($responseObject['hasMoreResults']) {
return $responseObject['maxOffset'] + 50;
} else {
return false;
}
}
@@ -75,8 +84,12 @@ while($latesEndTime - time() > 60){
// if there are any requests to do, do the first
if(count($task['requests']) > 0) {
doRequest($task['requests'][0], str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]), $username , $password);
array_shift($task['requests']);
$nextOffset = doRequest($task['requests'][0], str_replace(".json", ".csv", $downloadDir.'/'.$taskfiles[0]), $username , $password);
if($nextOffset){
$task['requests'][0]['offset'] = $nextOffset;
} else {
array_shift($task['requests']);
}
$taskString = json_encode($task);
$taskfile = fopen($taskDir.'/'.$taskfiles[0], 'w');
if($taskfile){