Skip to content

Instantly share code, notes, and snippets.

@cameronblandford
Last active January 23, 2021 18:34
Show Gist options
  • Save cameronblandford/49429486beed4586819af49fb45ab07b to your computer and use it in GitHub Desktop.
Save cameronblandford/49429486beed4586819af49fb45ab07b to your computer and use it in GitHub Desktop.
Get All Vaccine Providers in the Continental US
import axios from "axios";
import _ from "lodash";
import fs from "fs";
// HI: long: -178 to -155
// HI: lat: 18 to 29
// PR: long: -67 to -64
// PR: lat: 17 to 19
// AK: long: -180 to -125
// AK: lat: 50 to 70
// Continental US: long: -126 to -63
// Continental US: lat: 22 to 50
let startLong = -178;
let startLat = 18;
let endLong = -155;
let endLat = 29;
// max distance of one degree longitude === ~69mi
// max distance of one degree latitude === ~69mi
// because we're using circles to search,
// we have to use the circle to bound an inner square that's our effective search area
// The diameter of the circle will be sqrt(2)* the width of the square we want
// Since we're stepping half-degrees for lat and long, we need a square with width 35mi
// so our circle's diameter needs to be 35mi*sqrt(2), or 49.49mi
// this means that a radius of 25mi, or diameter of 50mi, will cover every point as we search
const longStep = 0.5;
const latStep = 0.5;
let dist = 25;
(async () => {
let errored = false;
for (let long = startLong; long <= endLong; long += longStep) {
errored = false;
const providers = [];
for (let lat = startLat; lat <= endLat; lat += latStep) {
let response = null;
try {
response = await axios.get(
`https://api.findertools.org/api/v1/public/providers/vaccinefinder/locations/?localization=${long},${lat}&distance=${dist}`
);
} catch (e) {
console.log(e);
errored = true;
}
const locations = response.data.features.map((x) => ({
coordinates: x.geometry.coordinates,
...x.properties,
}));
providers.push(...locations);
console.log(`[${long}, ${lat}]`);
console.log(locations);
if (errored) {
console.log("Error found");
break;
}
}
if (errored) {
// don't save errored files
console.log("Not saving file with error in it... skipping...");
continue;
}
console.log(providers);
const fileName = `./HI-providers-at-lat-${long}.json`;
fs.writeFile(fileName, JSON.stringify(providers, null, 1), (err) => {
if (err) {
console.log(`Error writing ${fileName}`, err);
} else {
console.log(`Successfully wrote ${fileName}`);
}
});
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment