-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata.php
29 lines (22 loc) · 1.01 KB
/
data.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
<?php
// COVID-19 Data Repository by the Center for Systems Science and Engineering (CSSE) at Johns Hopkins University
// https://github.com/CSSEGISandData/COVID-19
// Yesterday
$yesterday = strtotime("Yesterday");
$yesterdayFormatted = date("m-d-Y", $yesterday);
$url1 = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/' . $yesterdayFormatted . '.csv';
// Day Before Yesterday
$daybefore = strtotime("-1 day", $yesterday);
$daybeforeFormatted = date("m-d-Y", $daybefore);
$url2 = 'https://raw.githubusercontent.com/CSSEGISandData/COVID-19/master/csse_covid_19_data/csse_covid_19_daily_reports/' . $daybeforeFormatted . '.csv';
// Try to collect yesterday's file
$csv = file_get_contents($url1);
$newfile = 'regionalData/' . $yesterdayFormatted . '.csv';
// If it isn't there, try the day before
if ( $csv === FALSE ) {
$csv = file_get_contents($url2);
$newfile = 'regionalData/' . $daybeforeFormatted . '.csv';
}
// Save it
file_put_contents($newfile, $csv);
?>