import requests BASE_USAJOBS_URL = "https://data.usajobs.gov/api/jobs" STATECODES_URL = "http://stash.compjour.org/data/usajobs/us-statecodes.json" names = requests.get(STATECODES_URL).json() ## Everything from 1-8 on is the same: thelist = [] thelist.append(["State", "Job Count"]) for name, abbrev in names.items(): print("Getting: ", name) atts = {'CountrySubdivision': name, 'NumberOfJobs': 1} resp = requests.get(BASE_USAJOBS_URL, params = atts) jobcount = int(resp.json()['TotalJobs']) label = "US-" + abbrev thelist.append([label, jobcount]) chartcode = """

Hello chart

""" htmlfile = open("1-9.html", "w") htmlfile.write(chartcode % thelist) htmlfile.close()