Exemple #1
0
def run():
    print "Loading State data"
    xmldoc = minidom.parse('HealthMap/scripts/states.xml')
    cNodes = xmldoc.childNodes
    sList = cNodes[0].getElementsByTagName(
        "state")  # top level in DOM is States

    for state in sList:  # iterate through each State
        # create the State record in Region table
        print("%s (%s)" %
              (state.getAttribute('name'), state.getAttribute('abbrev')))
        reg = Region(state=state.getAttribute('abbrev'),
                     stateName=state.getAttribute('name'))
        reg.save()

        pList = state.getElementsByTagName("point")

        for point in pList:  # iterate through polyline points
            # create the Polyline record
            #            print ("lat:%s, lng:%s" % (point.getAttribute('lat'),point.getAttribute('lng')))
            line = Polyline(region=reg,
                            lat=point.getAttribute('lat'),
                            lng=point.getAttribute('lng'))
            line.save()

        print("... %s lat/lng points" % len(pList))
Exemple #2
0
def run():

    # clean up if necessary
    print "Loading County data"

    book = open_workbook('HealthMap/scripts/data.xls')
    sheet = book.sheet_by_index(1)
    
    for row_index in range(sheet.nrows):
        fips = sheet.cell(row_index,0).value
        state = sheet.cell(row_index,1).value
        county = sheet.cell(row_index,2).value
        if len(state)>1 and len(county)<1:      # state data row
            print state
        if len(fips)==5:
            state_reg = Region.objects.filter(stateName=state.strip())
            state_abbrev = state_reg[0].state    # get State abbrev
            reg = Region.objects.filter(state=state_abbrev, county=county)
            if reg:
               reg.delete()     # cleanup existing
            print("[%s] %s, County: %s (%s)" % (state_abbrev, state, county, fips))
            reg = Region(state=state_abbrev, stateName=state, county=county, fips=fips)
            reg.save()