コード例 #1
0
def getAllData():

    with open('fixtures/dist_prov.csv', 'rb') as csvfile:
        country = csv.reader(csvfile, delimiter=',', quotechar='"')
        for row in country:
            column_num = 0
            new_district = ""
            for column in row:
                if column_num == 1:
                    print "new_district="
                    new_district = column.replace('\n', ' ')
                    print new_district
                else:
                    print "query for province="
                    print column
                    getProvince = Province.objects.get(name=column,
                                                       country=country_id)
                    if getProvince:
                        new_dist = District(name=new_district,
                                            province=getProvince)
                        new_dist.save()
                    else:
                        new_prov = Province(name=column, country=country_id)
                        new_prov.save()
                        new_dist = District(name=new_district,
                                            province=getProvince)
                        new_dist.save()

                column_num = 1
コード例 #2
0
def getAllData():

    with open('fixtures/dist_prov.csv', 'rb') as csvfile:
        country = csv.reader(csvfile, delimiter=',', quotechar='"')
        for row in country:
            column_num = 0
            new_district = ""
            for column in row:
                if column_num == 1:
                    print "new_district="
                    new_district = column.replace('\n', ' ')
                    print new_district
                else:
                    print "query for province="
                    print column
                    getProvince = Province.objects.get(name=column, country=country_id)
                    if getProvince:
                        new_dist = District(name=new_district, province=getProvince)
                        new_dist.save()
                    else:
                        new_prov = Province(name=column, country=country_id)
                        new_prov.save()
                        new_dist = District(name=new_district, province=getProvince)
                        new_dist.save()

                column_num = 1
コード例 #3
0
def getAllData():

    with open('fixtures/timor-boundaries.csv', 'rb') as csvfile:
        country = csv.reader(csvfile, delimiter=',', quotechar='"')
        #check for province and add new ones
        for row in country:
            column_num = 0
            for column in row:
                if column_num == 0:
                    print "Province="
                    print column
                    try:
                        Province.objects.get(name=column, country=getCountry)
                    except Province.DoesNotExist:
                        new_prov = Province(name=column, country=getCountry)
                        new_prov.save()
                    print column
                column_num = column_num + 1

    with open('fixtures/timor-boundaries.csv', 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for distrcit and add new one
        for row in country2:
            print "take2"
            column_num = 0
            new_district = ""
            for column in row:
                if column_num == 0:
                    getProvince = Province.objects.get(name=column, country=getCountry)

                if column_num == 1:
                    print "District="
                    print column

                    try:
                        District.objects.get(name=column, province=getProvince)
                    except District.DoesNotExist:
                        new_district = District(name=column, province=getProvince)
                        new_district.save()

                column_num = column_num + 1

    with open('fixtures/timor-boundaries.csv', 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for distrcit and add new one
        for row in country2:
            print "take2"
            column_num = 0
            new_district = ""
            for column in row:
                if column_num == 0:
                    getProvince = Province.objects.get(name=column, country=getCountry)

                if column_num == 1:
                    getDistrict = District.objects.get(name=column, province=getProvince)

                if column_num == 2:
                    print "AdminLevelThree="
                    print column

                    try:
                        AdminLevelThree.objects.get(name=column, district=getDistrict)
                    except AdminLevelThree.DoesNotExist:
                        new_level_3 = AdminLevelThree(name=column, district=getDistrict)
                        new_level_3.save()

                column_num = column_num + 1
コード例 #4
0
def getAllData(getCountry,file_name):

    with open(file_name, 'rb') as csvfile:
        country = csv.reader(csvfile, delimiter=',', quotechar='"')
        print "PROVINCE (LEVEL 1) !!!!!!"
        #check for province and add new ones
        for row in country:
            column_num = 0
            for column in row:
                if column_num == 1:
                    print "Province="
                    print column
                    try:
                        Province.objects.get(name=column, country=getCountry)
                    except Province.DoesNotExist:
                        new_prov = Province(name=column, country=getCountry)
                        new_prov.save()
                    print column
                column_num = column_num + 1

    with open(file_name, 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for distrcit and add new one
        for row in country2:
            print "DISTRICTS (LEVEL 2) !!!!!!"
            column_num = 0
            for column in row:
                if column_num == 1:
                    getProvince = Province.objects.get(name=column, country=getCountry)

                if column_num == 2:
                    print "District="
                    print column

                    try:
                        District.objects.get(name=column, province=getProvince)
                    except District.DoesNotExist:
                        new_district = District(name=column, province=getProvince)
                        new_district.save()

                column_num = column_num + 1

    with open(file_name, 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for level3 and add new one
        for row in country2:
            print "LEVEL 3 !!!!!!"
            column_num = 0
            for column in row:
                if column_num == 1:
                    getProvince = Province.objects.get(name=column, country=getCountry)

                if column_num == 2:
                    getDistrict = District.objects.get(name=column, province=getProvince)

                if column_num == 3:
                    print "AdminLevelThree="
                    print column

                    try:
                        AdminLevelThree.objects.get(name=column, district=getDistrict)
                    except AdminLevelThree.DoesNotExist:
                        new_level_3 = AdminLevelThree(name=column, district=getDistrict)
                        new_level_3.save()

                column_num = column_num + 1

    with open(file_name, 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for village and add new one
        for row in country2:
            print "VILLAGE !!!!!"
            column_num = 0
            for column in row:
                if column_num == 1:
                    getProvince = Province.objects.get(name=column, country=getCountry)

                if column_num == 2:
                    getDistrict = District.objects.get(name=column, province=getProvince)

                if column_num == 3:
                    getAdminLevel3 = AdminLevelThree.objects.get(name=column, district=getDistrict)

                if column_num == 4:
                    print "Village="
                    print column

                    try:
                        Village.objects.get(name=column, admin_3=getAdminLevel3)
                    except Village.DoesNotExist:
                        new_level_3 = Village(name=column, admin_3=getAdminLevel3)
                        new_level_3.save()

                column_num = column_num + 1
コード例 #5
0
def getAllData(getCountry, file_name):

    with open(file_name, 'rb') as csvfile:
        country = csv.reader(csvfile, delimiter=',', quotechar='"')
        print "PROVINCE (LEVEL 1) !!!!!!"
        #check for province and add new ones
        for row in country:
            column_num = 0
            for column in row:
                if column_num == 1:
                    print "Province="
                    print column
                    try:
                        Province.objects.get(name=column, country=getCountry)
                    except Province.DoesNotExist:
                        new_prov = Province(name=column, country=getCountry)
                        new_prov.save()
                    print column
                column_num = column_num + 1

    with open(file_name, 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for distrcit and add new one
        for row in country2:
            print "DISTRICTS (LEVEL 2) !!!!!!"
            column_num = 0
            for column in row:
                if column_num == 1:
                    getProvince = Province.objects.get(name=column,
                                                       country=getCountry)

                if column_num == 2:
                    print "District="
                    print column

                    try:
                        District.objects.get(name=column, province=getProvince)
                    except District.DoesNotExist:
                        new_district = District(name=column,
                                                province=getProvince)
                        new_district.save()

                column_num = column_num + 1

    with open(file_name, 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for level3 and add new one
        for row in country2:
            print "LEVEL 3 !!!!!!"
            column_num = 0
            for column in row:
                if column_num == 1:
                    getProvince = Province.objects.get(name=column,
                                                       country=getCountry)

                if column_num == 2:
                    getDistrict = District.objects.get(name=column,
                                                       province=getProvince)

                if column_num == 3:
                    print "AdminLevelThree="
                    print column

                    try:
                        AdminLevelThree.objects.get(name=column,
                                                    district=getDistrict)
                    except AdminLevelThree.DoesNotExist:
                        new_level_3 = AdminLevelThree(name=column,
                                                      district=getDistrict)
                        new_level_3.save()

                column_num = column_num + 1

    with open(file_name, 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for village and add new one
        for row in country2:
            print "VILLAGE !!!!!"
            column_num = 0
            for column in row:
                if column_num == 1:
                    getProvince = Province.objects.get(name=column,
                                                       country=getCountry)

                if column_num == 2:
                    getDistrict = District.objects.get(name=column,
                                                       province=getProvince)

                if column_num == 3:
                    getAdminLevel3 = AdminLevelThree.objects.get(
                        name=column, district=getDistrict)

                if column_num == 4:
                    print "Village="
                    print column

                    try:
                        Village.objects.get(name=column,
                                            admin_3=getAdminLevel3)
                    except Village.DoesNotExist:
                        new_level_3 = Village(name=column,
                                              admin_3=getAdminLevel3)
                        new_level_3.save()

                column_num = column_num + 1
コード例 #6
0
def getAllData():

    with open('fixtures/timor-boundaries.csv', 'rb') as csvfile:
        country = csv.reader(csvfile, delimiter=',', quotechar='"')
        #check for province and add new ones
        for row in country:
            column_num = 0
            for column in row:
                if column_num == 0:
                    print "Province="
                    print column
                    try:
                        Province.objects.get(name=column, country=getCountry)
                    except Province.DoesNotExist:
                        new_prov = Province(name=column, country=getCountry)
                        new_prov.save()
                    print column
                column_num = column_num + 1

    with open('fixtures/timor-boundaries.csv', 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for distrcit and add new one
        for row in country2:
            print "take2"
            column_num = 0
            new_district = ""
            for column in row:
                if column_num == 0:
                    getProvince = Province.objects.get(name=column,
                                                       country=getCountry)

                if column_num == 1:
                    print "District="
                    print column

                    try:
                        District.objects.get(name=column, province=getProvince)
                    except District.DoesNotExist:
                        new_district = District(name=column,
                                                province=getProvince)
                        new_district.save()

                column_num = column_num + 1

    with open('fixtures/timor-boundaries.csv', 'rb') as csvfile2:
        country2 = csv.reader(csvfile2, delimiter=',', quotechar='"')
        #check for distrcit and add new one
        for row in country2:
            print "take2"
            column_num = 0
            new_district = ""
            for column in row:
                if column_num == 0:
                    getProvince = Province.objects.get(name=column,
                                                       country=getCountry)

                if column_num == 1:
                    getDistrict = District.objects.get(name=column,
                                                       province=getProvince)

                if column_num == 2:
                    print "AdminLevelThree="
                    print column

                    try:
                        AdminLevelThree.objects.get(name=column,
                                                    district=getDistrict)
                    except AdminLevelThree.DoesNotExist:
                        new_level_3 = AdminLevelThree(name=column,
                                                      district=getDistrict)
                        new_level_3.save()

                column_num = column_num + 1