OUTFN = "AK_NCDC_FirstOrderStations.json"

SAVEDATA = False
stationdata = []
for station in all_stations:
    path = os.path.join(endpoint_stations, "GHCND:{}".format(station))
    fullbase = requests.compat.urljoin(baseurl, path)
    r = requests.get(
        fullbase, 
        headers=custom_headers,
    )
    stationdata.append(json.loads(r.text))
if SAVEDATA:
    with open(OUTFN, "w") as fh:
        fh.write(json.dumps(stationdata, indent=2))

with open(OUTFN, "w") as fh:
    fh.write(json.dumps(stationdata, indent=2))

"""
Explanation: Get information for all stations in list and write out to JSON file
End of explanation
"""


[item["name"] for item in stationdata]

shortnamedic = {
    'FAIRBANKS INTERNATIONAL AIRPORT, AK US': "Fairbanks",
    'ANNETTE WEATHER SERVICE OFFICE AIRPORT, AK US': "Annette",
    'JUNEAU AIRPORT, AK US': "Juneau",
    'YAKUTAT AIRPORT, AK US': "Yakutat",
    'KODIAK AIRPORT, AK US': "Kodiak",
    'KING SALMON AIRPORT, AK US': "King Salmon",
    'HOMER AIRPORT, AK US': "Homer",
    'COLD BAY AIRPORT, AK US': "Cold Bay",
    'ANCHORAGE TED STEVENS INTERNATIONAL AIRPORT, AK US': "Anchorage",
    'ST PAUL ISLAND AIRPORT, AK US': "St. Paul",
    'BIG DELTA AIRPORT, AK US': "Big Delta",
    'GULKANA AIRPORT, AK US': "Gulkana",
    'VALDEZ WEATHER SERVICE OFFICE, AK US': "Valdez",
    'MCGRATH AIRPORT, AK US': "McGrath",
    'TALKEETNA AIRPORT, AK US': "Talkeetna",
    'BETTLES AIRPORT, AK US': "Bettles",
    'BETHEL AIRPORT, AK US': "Bethel",
    'KOTZEBUE RALPH WEIN MEMORIAL AIRPORT, AK ': "Kotzebue",
    'NOME MUNICIPAL AIRPORT, AK US': "Nome",
    'BARROW W POST W ROGERS AIRPORT, AK US': "Barrow (Utqiaġvik)"}

for item in stationdata:
    item['shortname'] = shortnamedic[item['name']]

with open(OUTFN, "w") as fh:
    fh.write(json.dumps(stationdata, indent=2))

"""
Explanation: Optional: Add short names and then save again
End of explanation
"""


