Skip to content

Instantly share code, notes, and snippets.

@mike-weiner
Last active May 12, 2021 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mike-weiner/b8f5ab903047a05c3d3579450c919be4 to your computer and use it in GitHub Desktop.
Save mike-weiner/b8f5ab903047a05c3d3579450c919be4 to your computer and use it in GitHub Desktop.
A Python version of a script that will use the open source Vaccine Spotter API to print out all vaccine centers in a specific city with which vaccine sites have appointments available.
import json
import requests
# get API url provided by https://www.vaccinespotter.org/api/
# this URL can be changed to any of the other states found at the URL above
URL = "https://www.vaccinespotter.org/api/v0/states/MN.json" # CHANGE STATE HERE
requestResponse = requests.get(URL)
parsedJSONResponse = requestResponse.json()
for location in parsedJSONResponse['features']:
if (location['properties']['city'].lower() == "rochester"): # CHANGE CITY NAME HERE (repleace rochester with the name of your city - city should be located in the state you are requesting)
print(location['properties']['name'])
print(location['properties']['address'])
if (str(location['properties']['appointments_available']).lower() == "true"):
print("Appointments Available: " + '\x1b[1;37;42m' + str(location['properties']['appointments_available']) + '\x1b[0m')
else:
print("Appointments Available: " + '\x1b[1;37;41m' + str(location['properties']['appointments_available']) + '\x1b[0m')
print(location['properties']['url'])
print("---")
@mike-weiner
Copy link
Author

mike-weiner commented May 12, 2021

Below is a PHP version of this script that could be used on a web server. This script is identical to the Python version above.

vaccine-spot.php

<?php
# Build HTML Output in a string to echo out
$html_output = "
    <html>
        <head>
            <meta charset='utf-8'>
            <title>Vaccine Spotter API Call Results</title>
            <meta name='description' content='This page is the result of the API call to http://vaccinespotter.org for the city and state you have selected.'>
            <meta name='viewport' content='width=device-width, initial-scale=1'>
        </head>
        <body>
            <div class='container'>
        ";

# get API url provided by https://www.vaccinespotter.org/api/
# this URL can be changed to any of the other states found at the URL above
$URL = "https://www.vaccinespotter.org/api/v0/states/MN.json";

# make JSON call and decode it
$getJSON = file_get_contents($URL,false);
$parsedJSONResponse = json_decode($getJSON);

# for every location in the JSON response, filter for the city name being looked for
foreach($parsedJSONResponse->features as $location) {
    if ( strcmp(strtolower($location->properties->city), "rochester") == 0) { # Search for all vaccine sites located in "rochester" (a city in Minnesota)
        $html_output = $html_output . "<div class='location-info-grouping'>";
        $html_output = $html_output . "<span class='location-name'>" . $location->properties->name . "</span><br>"; # print vaccine location name
        $html_output = $html_output . "<span class='location-address'>" . $location->properties->address . "</span><br>"; # print vaccine location street address

        # print vaccine location appointment availability
        if ($location->properties->appointments_available == 1) {
            $html_output = $html_output . "<span class='location-appointment-available' style='background-color:#149c38;color:white;font-weight:bold;padding:0rem 0.25rem;'>TRUE</span>" . "<br>";
        } elseif ($location->properties->appointments_available == 0) {
            $html_output = $html_output . "<span class='location-appointment-available' style='background-color:#d13111;color:white;font-weight:bold;padding:0rem 0.25rem;'>FALSE</span>" . "<br>";
        } else {
            $html_output = $html_output . "<span class='location-appointment-available' style='background-color:#d13111;color:white;font-weight:bold;padding:0rem 0.25rem;'>NIL</span>" . "<br>"; 
        }

        $html_output = $html_output . "<span class='location-url'>" . $location->properties->url . "</span><br>"; # print vaccine location URL to set up an appointment
        $html_output = $html_output . "</div><br>"; # close div for the current information grouping on the current location
    }
}

$html_output = $html_output . "</div></body></html>"; # Close HTML table
echo($html_output); # Return output to the front-end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment