-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathdata.js
90 lines (51 loc) · 2.28 KB
/
data.js
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
const api_url = 'https://api.covid19india.org/data.json';
const news_url = 'https://api.covid19india.org/updatelog/log.json';
async function getData() {
const response = await fetch(api_url);
const response50 = await fetch(news_url); //this is for the live news/updates
const data = await response.json();
const data50 = await response50.json();
document.getElementById("india-total").innerHTML = (data.statewise[0].confirmed);
// console.log(data.statewise[0].confirmed);
document.getElementById("india-recovered").innerHTML = (data.statewise[0].recovered);
// console.log(data.statewise[0].recovered);
document.getElementById("india-deaths").innerHTML = (data.statewise[0].deaths);
// console.log(data.statewise[0].deaths);
// console.log(data.statewise);
console.log(data);
}
getData();
var interval = setInterval(function () {
getData();
}, 60000);
/***********************************/
const loc_url = 'https://ipapi.co/json'; //location
const state_url = 'https://api.covid19india.org/data.json'; //statewise data
async function getData2() {
const response2 = await fetch(loc_url); //fetching location
const data2 = await response2.json();
const response3 = await fetch(state_url); //fetching statewise data
const data3 = await response3.json();
var country = data2.country_name; //country name
var state = data2.region; //state name
if (state == "National Capital Territory of Delhi") {
state = "Delhi";
}
// document.getElementById("state_name").innerHTML = "Total in " + state; //showing the state name
for (i = 1; i <= 37; i++) { //going through all the data
if (data3.statewise[i].state == "West Bengal") { //searching for the state name in the database
document.getElementById("state-total").innerHTML = data3.statewise[i].confirmed; //total cases
document.getElementById("state-recovered").innerHTML = data3.statewise[i].recovered; //recovered
document.getElementById("state-deaths").innerHTML = data3.statewise[i].deaths; //deaths
// console.log(data3);
/******************************************/
}
}
}
getData2();
var interval = setInterval(function () {
getData2();
}, 300000);
var interval = setInterval(function () {
getData3();
}, 300000);