Last active
March 6, 2020 21:02
-
-
Save fabriziosalmi/e3e6c72546cabfce1bda1fd5eca62aef to your computer and use it in GitHub Desktop.
COVID19 stats php script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// use: http(s)://PHP_HOST/covid19_stats.php?date=03-03-2020 | |
// data source: https://github.com/CSSEGISandData/COVID-19/tree/master/csse_covid_19_data/csse_covid_19_daily_reports | |
error_reporting(E_ERROR); | |
$url = "https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/".$_GET["date"].".csv"; | |
$data = file_get_contents($url); | |
file_put_contents("last.csv", $data); | |
$csv = array_map('str_getcsv', file('last.csv')); | |
foreach($csv as $row) { | |
$cases = $row[3]; | |
$dead = $row[4]; | |
$sum+= $cases; | |
$dsum+= $dead; | |
foreach($row as $k) { | |
} | |
} | |
$fatality=($dsum*100)/$sum; | |
// JSON API | |
$json = array( | |
"date" => $_GET["date"], | |
"confirmed" => $sum, | |
"deaths" => $dsum, | |
"fatality" => round($fatality, 3) | |
); | |
// JSON OUTPUT | |
header('Content-Type: application/json'); | |
echo json_encode($json); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment