|
Hello: In the link an application / example is delivered where you work with the PHPRunner API and elsewhere, more or less the same is done, but in this case, retrieving the data and loading it into the Database, showing the data from the database. An example of the code:
<?php
@ini_set("display_errors","1");
@ini_set("display_startup_errors","1");
require_once __DIR__ . '/../../ComponentCode/unirest_3.0.4/autoload.php';
function valueToZero($val){
return empty($val)?0:$val;
}
$session_name = session_id();
// Delete the covid_statistics of session
$sql="delete FROM covid_statistics where SessionName = '$session_name'";
$resql=db_query($sql,$conn);
$response = Unirest\Request::get("https://covid-193.p.rapidapi.com/statistics",
array(
"X-RapidAPI-Host" => "covid-193.p.rapidapi.com",
"X-RapidAPI-Key" => "4bc3052c61msh7345bc8ec10474ap10192ejsn016e636a3859"
)
);
$a = $response->code; // HTTP Status code
$b = $response->headers; // Headers
$c = $response->body; // Parsed body
$d = $response->raw_body; // Unparsed body
$f = json_decode($d,true);
// var_dump($f); // DUMP pf array
$count = count($f["response"]);
foreach($f["response"] as $response) {
// $SessionName,
$country = $response['country'];
$day = $response['day'];
$CasesNew = $response['cases']['new'];
$CasesActive = $response['cases']['active'];
$CasesCritical = $response['cases']['critical'];
$CasesRecovered = $response['cases']['recovered'];
$CasesTotal = $response['cases']['total'];
$DeathsNew = $response['deaths']['new'];
$DeathsTotal = $response['deaths']['total'];
$TestTotal = $response['tests']['total'];
$CasesNew = valueToZero($CasesNew); // if Null = 0
$CasesActive = valueToZero($CasesActive); // if Null = 0
$CasesCritical = valueToZero($CasesCritical); // if Null = 0
$CasesRecovered = valueToZero($CasesRecovered); // if Null = 0
$CasesTotal = valueToZero($CasesTotal); // if Null = 0
$DeathsNew = valueToZero($DeathsNew); // if Null = 0
$DeathsTotal = valueToZero($DeathsTotal); // if Null = 0
$TestTotal = valueToZero($TestTotal); // if Null = 0
$sql="insert INTO covid_statistics
(SessionName,country,dataDay,CasesNew,CasesActive,CasesCritical,CasesRecovered,CasesTotal,DeathsNew,DeathsTotal,TestTotal)
VALUES ('$session_name','$country','$day',$CasesNew,$CasesActive,$CasesCritical,$CasesRecovered,$CasesTotal,$DeathsNew,$DeathsTotal,$TestTotal)";
$resql=db_query($sql,$conn);
}
Cheers,
|