Skip to content
This repository has been archived by the owner on Jan 31, 2021. It is now read-only.

Commit

Permalink
reformatted data and website
Browse files Browse the repository at this point in the history
to show only available slots and all sites
  • Loading branch information
99littlebugs committed Jan 13, 2021
1 parent 57982ef commit bf8a551
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 93 deletions.
34 changes: 33 additions & 1 deletion build.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,37 @@ const handlebars = require('handlebars');
const fs = require("fs");
const path = require('path');

handlebars.registerHelper('date', function (date) {
const options = { weekday: 'short', month: 'short', day: 'numeric' };
return new Date(date).toLocaleDateString('en-us', options);
});

const template = handlebars.compile(fs.readFileSync(path.join("site", "index.hbs")).toString('utf8'));
fs.writeFileSync(path.join("site", "index.html"), template(JSON.parse(fs.readFileSync(path.join("data", "ny_state.json")))));
const data = JSON.parse(fs.readFileSync(path.join("data", "ny_state.json")));

const events = [];
const sites = [];

for (const site of data.sites) {
for (const event of site.events) {
event.site = site;
delete event.site.events;
events.push(event);
}

delete site.events;
sites.push(site);
}

fs.writeFileSync(path.join("site", "index.html"), template({ sites: sites.sort(sortByProperty("name")), events: events.sort(sortByProperty("date")) }));

function sortByProperty(property) {
return function (a, b) {
if (a[property] > b[property])
return 1;
else if (a[property] < b[property])
return -1;

return 0;
}
}
59 changes: 23 additions & 36 deletions scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const fs = require("fs");
const path = require('path');


var nyGovSites = [{
const nyGovSites = [{
name: "NYS DOH Hospital / FQHC Scheduling COVID-19 Sutphin Health Center",
link: "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50501251",
address: {
Expand Down Expand Up @@ -59,6 +59,17 @@ var nyGovSites = [{
city: "Oceanside",
state: "NY",
zip: "11598"
},
},
{
name: "NYS COVID Vaccine POD - JAVax - Manhattan, N.Y.",
link: "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50502320",
address: {
name: "JAVax Manhattan, N.Y.",
street: "429 11th Avenue",
city: "New York",
state: "NY",
zip: "10018"
}
}];

Expand All @@ -67,50 +78,26 @@ let promises = [];

for (const site of nyGovSites) {
promises.push(axios.get(site.link).then(res => {
site.events = [];
const $ = cheerio.load(res.data);
const eventsWeb = $(".event-type");
for (const event of eventsWeb) {
events.push({
name: site.name,
link: site.link,
address: site.address,
date: $(event).find("div div:contains('Date:'):last").first().text(),
time: $(event).find("div div:contains('Time:'):last").first().text(),
available: $(event).find("button").text() !== "Event Full"
})
const isAvailable = $(event).find("button").text() !== "Event Full";
if (isAvailable) {
site.events.push({
date: new Date($(event).find("div div:contains('Date:'):last").first().text().substring(6) + " UTC"),
time: $(event).find("div div:contains('Time:'):last").first().text().substring(6),
available: isAvailable
})
}
}
}).catch(err => {
console.error(err.message + ": " + err.config.url);
}));
}

Promise.all(promises).then(() => {
const data = JSON.stringify({ events: events.sort(sortByProperties("date", "time", "name")) }, null, 2);
const data = JSON.stringify({ sites: nyGovSites }, null, 2);
const filename = path.join("data", "ny_state.json");
fs.writeFileSync(path.resolve(filename), data);
});

function sortByProperties(property1, property2, property3) {
return function (a, b) {
var sort = sortByProperty(property1)(a, b);
if (sort !== 0) {
return sort;
}
sort = sortByProperty(property2)(a, b);
if (sort !== 0) {
return sort;
}
return sortByProperty(property3);
}
}

function sortByProperty(property) {
return function (a, b) {
if (a[property] > b[property])
return 1;
else if (a[property] < b[property])
return -1;

return 0;
}
}
});
116 changes: 60 additions & 56 deletions site/index.hbs
Original file line number Diff line number Diff line change
@@ -1,83 +1,87 @@
<!DOCTYPE html>
<html lang="en">

<head>

<!-- Basic Page Needs
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<!-- Basic Page Needs -->
<meta charset="utf-8">
<title>Vaccine Site Finder</title>
<meta name="description" content="NY State vaccination appointments seem to be spread across multiple websites, making it challenging to see where appointments are available.
This website aims to solve that problem by aggregating the views of the many different sites to a single dashboard.">

<!-- Mobile Specific Metas
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<!-- Mobile Specific Metas -->
<meta name="viewport" content="width=device-width, initial-scale=1">

<!-- FONT
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<!-- Font -->
<link href="//fonts.googleapis.com/css?family=Raleway:400,300,600" rel="stylesheet" type="text/css">

<!-- CSS
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<!-- CSS -->
<link rel="stylesheet" href="css/normalize.css">
<link rel="stylesheet" href="css/skeleton.css">
<link rel="stylesheet" href="css/site.css">

<!-- Favicon https://www.iconfinder.com/icons/5991794/coronavirus_cure_injection_needle_vaccination_vaccine_icon
–––––––––––––––––––––––––––––––––––––––––––––––––– -->

<!-- Favicon https://www.iconfinder.com/icons/5991794/coronavirus_cure_injection_needle_vaccination_vaccine_icon -->
<link rel="apple-touch-icon" sizes="180x180" href="images/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
<link rel="manifest" href="images/site.webmanifest">
<link rel="mask-icon" href="images/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="images/favicon.ico">
<meta name="msapplication-TileColor" content="#ffc40d">
<meta name="msapplication-config" content="images/browserconfig.xml">
<meta name="theme-color" content="#ffffff">

<link rel="icon" type="image/png" sizes="32x32" href="images/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="images/favicon-16x16.png">
<link rel="manifest" href="images/site.webmanifest">
<link rel="mask-icon" href="images/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="images/favicon.ico">
<meta name="msapplication-TileColor" content="#ffc40d">
<meta name="msapplication-config" content="images/browserconfig.xml">
<meta name="theme-color" content="#ffffff">
</head>

<body>

<!-- Primary Page Layout
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
<div class="container">
<div class="row">
<h1 class="p-t-5">Vaccine Site Finder</h1>
<p>This site aims to make finding a vaccine appointment a little bit easier. It is currently focused on the Nassau
County and Queens area and is updated periodically.</p>
<p>This site is not affiliated with NY State or any goverment or health agency. For feature requests, comments, or to help please contact us through <a target="_blank" href="https://github.com/99littlebugs/vaccine-site-finder">Github</a>.</p>
<table>
<tr>
<th>Address</th>
<th>Date</th>
<th>Time</th>
<th></th>
</tr>
{{#each events}}
<tr>
<td>
<strong>{{address.name}}</strong><br>
{{address.street}}<br>
{{address.city}}, {{address.state}} {{address.zip}}
</td>
<td>{{date}}</td>
<td>{{time}}</td>
{{#if available}}
<td><a target="_blank" class="button button-primary" href="{{link}}">Book</a></td>
{{else}}
<td><a target="_blank" class="button" href="{{link}}">View</a></td>
{{/if}}
</tr>
{{/each}}
</table>
County, Queens, and Manhattan area and is updated multiple times per hour.</p>
<p>This site is not affiliated with NY State or any goverment or health agency. For feature requests, comments, or
to help please contact us through <a target="_blank"
href="https://github.com/99littlebugs/vaccine-site-finder">Github</a>.</p>
<h3>Sites and times with availability:</h2>
<p>The following events are showing with availability. When you click "Book" you will be brought to the NY
Health site. You may need to scroll down to find the day that you need.</p>
<table class="u-full-width">
<tr>
<th>Address</th>
<th>Date</th>
<th>Time</th>
<th></th>
</tr>
{{#each events}}
<tr>
<td>
<strong>{{site.address.name}}</strong><br>
{{site.address.street}}<br>
{{site.address.city}}, {{site.address.state}} {{site.address.zip}}
</td>
<td>{{date date}}</td>
<td>{{time}}</td>
<td><a target="_blank" class="u-pull-right button button-primary" href="{{site.link}}">Book</a></td>
</tr>
{{/each}}
</table>
<h3>Sites:</h2>
<p>These are the sites that we are currently tracking.</p>
<table class="u-full-width">
<tr>
<th>Name</th>
<th>Address</th>
<th></th>
</tr>
{{#each sites}}
<tr>
<td>{{name}}</td>
<td>
<strong>{{address.name}}</strong><br>
{{address.street}}<br>
{{address.city}}, {{address.state}} {{address.zip}}
</td>
<td><a target="_blank" class="u-pull-right button" href="{{site.link}}">View</a></td>
</tr>
{{/each}}
</table>
</div>
</div>

<!-- End Document
–––––––––––––––––––––––––––––––––––––––––––––––––– -->
</body>

</html>

0 comments on commit bf8a551

Please sign in to comment.