Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
neelpy committed May 1, 2021
0 parents commit d0385d8
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Neel Patel

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# cowin
CoWIN Availability
21 changes: 21 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<html>
<head>
<title>CoWIN Availibility</title>
</head>
<body>
<form onsubmit="check()">
State: Gujarat, District: Ahmedabad Corporation<br>
<label>Date:</label>
<input type="number" id="date">
Age: <label for="18">18+</label>
<input type="radio" id="18" name="age" value="18" checked>
<label for="45">45+</label>
<input type="radio" id="45" name="age" value="45">
<input type="button" value="Fetch Available Centers" onclick="check()">
</form>
<div id="results">

</div>
<script src="script.js"></script>
</body>
</html>
51 changes: 51 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var dateField = document.getElementById('date');
var age18 = document.getElementById('18');
var results = document.getElementById('results');

function getDate() {
const d = dateField.value;
return (d.length === 1 ? '0' : '') + d + '-05-2021'
}
function getAge() {
return age18.checked ? 18 : 45;
}

function get(callback) {
var req = new XMLHttpRequest();
const district_id = '770';
const date = getDate();
const url = `https://cdn-api.co-vin.in/api/v2/appointment/sessions/public/calendarByDistrict?district_id=${district_id}&date=${date}`;
req.open('GET', url, true);
req.responseType = 'json';
req.onload = function() {
var status = req.status;
if (status === 200)
callback(null, req.response);
else
callback(status, req.response);
};
req.send();
}

function check() {
get((err, res) => {
if (err) return alert(`Error: ${err}`)
console.log(res);
const date = getDate();
const age = getAge();
console.log(age);
const available = res.centers.filter(center => {
return center.sessions.some(s => (s.available_capacity > 0 && s.min_age_limit === age))
})
console.log(available);
const template = center => `
<div class="center" style="border: 1px solid black">
<b>${center.name}, Pincode: ${center.pincode}</b><br>
${center.sessions.filter(s => s.available_capacity > 0).map(s => s.date + ': ' + s.available_capacity).join('<br>')}<br>
</div>
`;
if (available.length === 0)
results.innerHTML = 'No 18+ centers available :('
results.innerHTML = available.map(c => template(c)).join(' ')
})
}

0 comments on commit d0385d8

Please sign in to comment.