This repository has been archived by the owner on Nov 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 131
/
data_loading.html
61 lines (47 loc) · 1.96 KB
/
data_loading.html
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
53
54
55
56
57
58
59
60
61
<!--
Copyright 2020 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<html>
<head>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
</head>
<body>
<!-- This will be updated once data loads -->
<p>The dataset currently contains <span id="count"></span> records, here are the last few:</p>
<!-- This table will be populated with our output -->
<table id="table" border="1"></table>
<script>
// Load the latest data for each region
$.getJSON(`https://storage.googleapis.com/covid19-open-data/v2/latest/main.json`, response => {
const data = response.data;
// Update the count of records
$('#count').text = data.length;
// Use a string variable to build HTML output for simplicity (use Buffer in production)
let output = '';
// Get the column names from the first record
const columns = Object.keys(data[0]);
// Write table headers
output += `<tr>`;
columns.forEach(key => output += `<th>${key}</th>`);
output += `</tr>`;
// Write the last 5 rows of the table
data.slice(-5).forEach(row => {
output += `<tr>`;
columns.forEach(key => output += `<td>${row[key]}</td>`);
output += `</tr>`;
});
// Update the table
$('#table').html(output);
});
</script>
</body>
</html>