-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAPI_Vaccination.js
More file actions
92 lines (90 loc) · 3.52 KB
/
Copy pathAPI_Vaccination.js
File metadata and controls
92 lines (90 loc) · 3.52 KB
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
91
92
function StringBuilder(value) {
this.strings = new Array("");
this.append(value);
}
StringBuilder.prototype.append = function (value) {
if (value) {
this.strings.push(value);
}
};
StringBuilder.prototype.clear = function () {
this.strings.length = 1;
};
StringBuilder.prototype.toString = function () {
return this.strings.join("");
};
function getSlotDetails() {
var date = new Date();
var dd = String(date.getDate()).padStart(2, '0');
var mm = String(date.getMonth() + 1).padStart(2, '0');
var yyyy = date.getFullYear();
date = dd + '-' + mm + '-' + yyyy;
var sb = new StringBuilder();
sb.append(`<div class="table-responsive">
<table class="table table-bordered table-striped table-hover" id="myTable">
<thead >
<tr>
<th>#</th>
<th>Pincode</th>
<th>Center Name</th>
<th>Fee</th>
<th>Slots</th>
<th>Age</th>
<th>Vaccine</th>
</tr>
</thead>
<tbody>`);
// file = 'response.json';
// fetch(file)
// .then(response => response.json())
// .then(jsonResponse => {
// var data = jsonResponse.centers;
return axios({
"method": "GET",
"url": `https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=395&date=${date}`,
"headers": {
"content-type": "application/json",
"accept": "application/json"
}
})
.then((response) => {
var data = response.data.centers;
console.log(data);
var chk = 0;
if (data) {
for (var i = 0; i < data.length; i++) {
var serial = '<tr> <th scope="row">' + (i + 1) + '</th>';
var name = '<td>' + data[i].name + '</td>';
var pincode = '<td>' + data[i].pincode + '</td>';
var fee_type = '<td>' + data[i].fee_type + '</td>';
var fee = 0;
var timings = '<td>' + data[i].from + ' - ' + data[i].to + '</td>';
for (var j = 0; j < data[i].sessions.length; j++) {
if (data[i].sessions[j].available_capacity > 0) {
var availability = '<td>' + data[i].sessions[j].available_capacity + '</td>';
var min_age = '<td>' + data[i].sessions[j].min_age_limit + '+</td>';
var vaccine = '<td>' + data[i].sessions[j].vaccine + '</td></tr>';
// if (data[i].fee_type == 'Paid') {
// fee = '<td>' + data[i].vaccine_fees[0].fee + '</td>';
// sb.append(serial + name + address + fee_type + fee + timings + availability + min_age + vaccine);
// }
// else {
sb.append(serial + pincode + name + fee_type + availability + min_age + vaccine);
//}
chk = 1;
}
}
}
}
sb.append('</tbody> </table > </div >');
if (chk === 0) {
sb.clear();
sb.append('<center><em><h4>No Slots are available. Please check again later.</h4></em></center>');
}
console.log(sb.toString());
//sb.clear();
//document.write(sb.toString());
document.getElementById("table").innerHTML = sb.toString();
})
}
getSlotDetails();