Example #1
0
def getData(states, stateNumbers):
    for key in stateNumbers:
        url = "https://api.census.gov/data/2018/acs/acs1?get=NAME,B01001_001E,B01001_002E,B01002_001E,B19081_001E,B19081_002E,B19081_003E,B19081_004E,B19081_005E,B17001_002E,B25002_002E&for=congressional+district:*&in=state:"+stateNumbers[key]
        resp = getJsonFromUrl(url)
        state = State(resp[1][len(resp[1]) - 2], key)
        districts = state.getDistricts()
        for cd in range(1, len(resp)):
            population = resp[cd][1]
            malePopulation = resp[cd][2]
            medianAge = resp[cd][3]
            meanIncome = [
                resp[cd][4],
                resp[cd][5],
                resp[cd][6],
                resp[cd][7],
                resp[cd][8]
            ]
            povertyPopulation = resp[cd][9]
            numHouseholds = resp[cd][10]
            congressionalDistrict = resp[cd][len(resp[cd]) - 1]
            district = District(key, congressionalDistrict)
            district.setPopulation(population)
            district.setGenderRatio(malePopulation)
            district.setMedianAge(medianAge)
            district.setMeanIncome(meanIncome)
            district.setPovertyRate(povertyPopulation)
            district.setNumHouseholds(numHouseholds)
            district.setWikiPage(key, congressionalDistrict)
            districts.append(district)
        states[key] = state
Example #2
0
def getStateNumbers():
    states = {}
    url = "https://api.census.gov/data/2018/acs/acs1?get=NAME,group(B01001)&for=state"
    data = getJsonFromUrl(url)
    for index in range(1, len(data)):
        states[data[index][0]] = data[index][len(data[index]) - 1]
    # states["arkansus"] = "01"
    return states
Example #3
0
def getData(states, stateNumbers):
    for key in stateNumbers:
        url = "https://api.census.gov/data/2018/acs/acs1?get=NAME,B02001_001E,B02001_002E,B02001_003E,B02001_004E,B02001_005E,B02001_006E,B02001_007E&for=congressional+district:*&in=state:" + stateNumbers[
            key]
        resp = getJsonFromUrl(url)
        state = resp[1][len(resp[1]) - 2]
        congressional_district = resp[1][len(resp[1]) - 1]
        data = []
        for i in range(1, len(resp)):
            data.append(resp[i])
        states[state] = data
Example #4
0
 def test_json_from_url(self):
     url = "https://api.census.gov/data/2018/acs/acs1?get=NAME,group(B01001)&for=us:1"
     data = getJsonFromUrl(url)
     assert type(data) is list