-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
52 lines (51 loc) · 2.21 KB
/
index.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, 'https://spreadsheets.google.com/feeds/list/1lwnfa-GlNRykWBL5y7tWpLxDoCfs8BvzWxFjeOZ1YJk/1/public/values?alt=json');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_ENCODING, '');
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.87 Safari/537.36');
$data = curl_exec($curl);
// ------------------------------------------------------------------------
if(curl_errno($curl) == 28) {
$timeout = true;
}else{
$timeout = false;
}
curl_close($curl);
if($timeout) {
echo 'Timeout!'."\n";
exit;
}
if(trim($data) == '') {
echo 'Curl data empty!'."\n";
exit;
}
// ------------------------------------------------------------------------
$json = json_decode(mb_convert_encoding($data, 'HTML-ENTITIES', 'UTF-8'));
// ------------------------------------------------------------------------
if(!isset($json->{'feed'}->{'entry'})) {
$found = false;
echo 'No data!' . "\n";
exit;
}else {
$found = true;
}
$updatedDatetimeUtc = $json->{'feed'}->{'updated'}->{'$t'};
$updatedDatetime = trim(date("Y-m-d H:i:s", strtotime($updatedDatetimeUtc)));
echo 'Updated Time UTC: ' . $updatedDatetimeUtc . "\n";
// ------------------------------------------------------------------------
if($found) {
$counter = 1;
foreach($json->{'feed'}->{'entry'} as $eachData) {
$country = trim($eachData->{'title'}->{'$t'});
$confirmedCases = trim($eachData->{'gsx$confirmedcases'}->{'$t'});
$reportedDeaths = trim($eachData->{'gsx$reporteddeaths'}->{'$t'}) != '' ? trim($eachData->{'gsx$reporteddeaths'}->{'$t'}) : 0;
echo $counter . '. ' . $country . ' - Confirmed Cases: ' . $confirmedCases . ' - Reported Deaths: ' . $reportedDeaths . "\n";
$counter++;
}
}
?>