US Universities with Late Application Deadlines

Based on https://blog.prepscholar.com/colleges-with-late-application-deadlines-complete-list.

Code to fetch information about the universities from the list above:

# %%
#!pip3 install requests
# !pip3 install ipywidgets

import requests
import csv
from typing import List, Dict, Optional
from ipywidgets import IntProgress
from IPython.display import display

# %%
MAPS_API_KEY = "<YOUR_KEY>"

def fetch_uni_info(name: str) -> Optional[Dict[str, str]]:
    base_url_place = 'https://maps.googleapis.com/maps/api/place/findplacefromtext/json'
    params_place = {
        'input': name,
        'inputtype': 'textquery',
        'fields': 'name,place_id',
        'types': '(universities)',
        # 'region': 'us',
        # 'circle': '50000@41.071533,-97.785450',
        'key': MAPS_API_KEY,
    }

    response_place = requests.get(base_url_place, params=params_place)
    if response_place.status_code != 200:
        return None

    data_place = response_place.json()

    if len(data_place["candidates"]) < 1:
       return None

    place_id = data_place["candidates"][0]["place_id"]

    base_url_info = 'https://maps.googleapis.com/maps/api/place/details/json'
    params_info = {
        'place_id': place_id,
        'fields': 'name,address_components,adr_address,formatted_address,website,geometry/location',
        'key': MAPS_API_KEY
    }

    response_info = requests.get(base_url_info, params=params_info)
    if response_info.status_code != 200:
       return None

    data_info = response_info.json()['result']

    components = data_info["address_components"]
    # print(components)
    city = next((e["short_name"] for e in components if "locality" in e["types"] or "postal_town" in e["types"]), None)
    state = next(e["short_name"] for e in components if "administrative_area_level_1" in e["types"])
    country = next(e["short_name"] for e in components if "country" in e["types"])

    lat = data_info["geometry"]["location"]["lat"]
    lon = data_info["geometry"]["location"]["lng"]

    return {
        "website": data_info["website"] if "website" in data_info else None,
        "city": city,
        "state": state,
        "country": country,
        "formatted_address": data_info["formatted_address"],
        "lat": lat,
        "lon": lon
    }

fetch_uni_info("Yonsei University")

# %%
unis = []

with open('input.csv') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    is_header = True
    for row in csv_reader:
        if is_header:
            is_header = False
            continue
        unis.append({"name": row[0], "deadline": row[1]})

unis


# %%
uni_infos = {}

# %%
f = IntProgress(min=0, max=len(unis))
display(f)

for uni in unis:
    f.value += 1
    uni_name = uni["name"]
    if uni_name in uni_infos:
        continue
    print("Fetching info for " + uni_name)
    uni_info = fetch_uni_info(uni_name)
    if uni_info:
        uni_infos[uni_name] = uni_info

# %%
print("Len:", len(uni_infos.keys()))
list(uni_infos.keys())

# %%
header = ["University", "Application Deadline", "Website", "City", "State", "Country", "Full Address", "Latitude", "Longitude"]

def build_row(uni_input: Dict[str, str]) -> List[str]:
    name = uni_input["name"]
    deadline = uni_input["deadline"]
    website, city, state, country, formatted_address, lat, lon = None, None, None, None, None, None, None
    if name in uni_infos:
        info = uni_infos[name]
        website = info["website"]
        city = info["city"]
        state = info["state"]
        country = info["country"]
        formatted_address = info["formatted_address"]
        lat = info["lat"]
        lon = info["lon"]

    return [name, deadline, website, city, state, country, formatted_address, lat, lon]

build_row(unis[0])

# %%

with open('unis_with_late_deadlines.csv', 'w', encoding='UTF-8') as f:
    writer = csv.writer(f)

    writer.writerow(header)

    writer.writerows(map(lambda uni: build_row(uni), unis))

# %%
# Produce JS code for adding markers to the map. See https://developers.google.com/maps/documentation/javascript/markers#accessible

print("const unis: [google.maps.LatLngLiteral, string][] = [")

for uni in unis:
    name = uni["name"]
    deadline = uni["deadline"]
    if name not in uni_infos:
        continue
    info = uni_infos[name]
    full_name = name + " (" + deadline + ")"
    print("    [{ lat: " + str(info["lat"]) + ", lng: " + str(info["lon"]) + " }, \"" + full_name + "\", \"" + deadline + "\"],")

print("]")