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

Commit

Permalink
Promises and sorting
Browse files Browse the repository at this point in the history
  • Loading branch information
99littlebugs committed Jan 11, 2021
1 parent afc0a01 commit b3bb90f
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 14 deletions.
98 changes: 91 additions & 7 deletions data/ny_state.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"state": "NY",
"zip": "11435"
},
"date": "Date: January 12, 2021",
"date": "Date: February 02, 2021",
"time": "Time: 10:00 AM - 05:00 PM",
"available": false
},
Expand All @@ -23,7 +23,7 @@
"state": "NY",
"zip": "11435"
},
"date": "Date: January 19, 2021",
"date": "Date: February 09, 2021",
"time": "Time: 10:00 AM - 05:00 PM",
"available": false
},
Expand All @@ -37,7 +37,7 @@
"state": "NY",
"zip": "11435"
},
"date": "Date: January 26, 2021",
"date": "Date: February 16, 2021",
"time": "Time: 10:00 AM - 05:00 PM",
"available": false
},
Expand All @@ -51,10 +51,38 @@
"state": "NY",
"zip": "11435"
},
"date": "Date: February 02, 2021",
"date": "Date: February 23, 2021",
"time": "Time: 10:00 AM - 05:00 PM",
"available": false
},
{
"name": "Northwell CoVID-19 Vaccination Program: Nassau County - Lake Success",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50500075",
"address": {
"name": "Lake Success/New Hyde Park",
"street": "1111 Marcus Avenue",
"city": "New Hyde Park",
"state": "NY",
"zip": "11042"
},
"date": "Date: January 11, 2021",
"time": "Time: 07:00 AM - 09:45 PM",
"available": true
},
{
"name": "Northwell CoVID-19 Vaccination Program: Nassau County - Elmont",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50501190",
"address": {
"name": "NYRA/Belmont",
"street": "2150 Hempstead Turnpike",
"city": "Elmont",
"state": "NY",
"zip": "11053"
},
"date": "Date: January 11, 2021",
"time": "Time: 12:00 PM - 07:45 PM",
"available": false
},
{
"name": "NYS DOH Hospital / FQHC Scheduling COVID-19 Sutphin Health Center",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50501251",
Expand All @@ -65,10 +93,52 @@
"state": "NY",
"zip": "11435"
},
"date": "Date: February 09, 2021",
"date": "Date: January 12, 2021",
"time": "Time: 10:00 AM - 05:00 PM",
"available": false
},
{
"name": "FIRST DOSE - NYS DOH Hospital/FQHC Appointment Scheduling COVID-19 at Mount Sinai South Nassau",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50500074",
"address": {
"name": "Mount Sinai South Nassau",
"street": "One Healthy Way",
"city": "Oceanside",
"state": "NY",
"zip": "11598"
},
"date": "Date: January 13, 2021",
"time": "Time: 03:00 PM - 11:00 PM",
"available": false
},
{
"name": "FIRST DOSE - NYS DOH Hospital/FQHC Appointment Scheduling COVID-19 at Mount Sinai South Nassau",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50500074",
"address": {
"name": "Mount Sinai South Nassau",
"street": "One Healthy Way",
"city": "Oceanside",
"state": "NY",
"zip": "11598"
},
"date": "Date: January 14, 2021",
"time": "Time: 07:00 AM - 03:00 PM",
"available": false
},
{
"name": "FIRST DOSE - NYS DOH Hospital/FQHC Appointment Scheduling COVID-19 at Mount Sinai South Nassau",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50500074",
"address": {
"name": "Mount Sinai South Nassau",
"street": "One Healthy Way",
"city": "Oceanside",
"state": "NY",
"zip": "11598"
},
"date": "Date: January 15, 2021",
"time": "Time: 09:00 AM - 05:00 PM",
"available": false
},
{
"name": "NYS DOH Hospital / FQHC Scheduling COVID-19 Sutphin Health Center",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50501251",
Expand All @@ -79,10 +149,24 @@
"state": "NY",
"zip": "11435"
},
"date": "Date: February 16, 2021",
"date": "Date: January 19, 2021",
"time": "Time: 10:00 AM - 05:00 PM",
"available": false
},
{
"name": "NYS DOH Hospital/FQHC Appointment Scheduling COVID-19 at Nassau University Medical Center",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50500121",
"address": {
"name": "Nassau University Medical Center",
"street": "2201 Hempstead Turnpike",
"city": "East Meadow",
"state": "NY",
"zip": "11554"
},
"date": "Date: January 21, 2021",
"time": "Time: 06:15 AM - 06:00 PM",
"available": false
},
{
"name": "NYS DOH Hospital / FQHC Scheduling COVID-19 Sutphin Health Center",
"link": "https://apps.health.ny.gov/doh2/applinks/cdmspr/2/counties?OpID=50501251",
Expand All @@ -93,7 +177,7 @@
"state": "NY",
"zip": "11435"
},
"date": "Date: February 23, 2021",
"date": "Date: January 26, 2021",
"time": "Time: 10:00 AM - 05:00 PM",
"available": false
}
Expand Down
42 changes: 35 additions & 7 deletions scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,24 +63,52 @@ var nyGovSites = [{
}];

const events = [];
let promises = [];

for (const site of nyGovSites) {
axios.get(site.link).then(res => {
promises.push(axios.get(site.link).then(res => {
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(),
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 data = JSON.stringify(events, null, 2);
const filename = path.join("data", "ny_state.json");
fs.writeFileSync(path.resolve(filename), data);
});
Promise.all(promises).then(() => {
const data = JSON.stringify(events.sort(sortByProperties("date", "time", "name")), 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;
}
}

0 comments on commit b3bb90f

Please sign in to comment.