def load_transactions(transaction_file, verbose=False): with open(transaction_file, 'r') as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if Transaction.objects.count() == 0: skip_lookup = True for row in reader: try: amount_prime = float(row[2]) except: amount_prime = None doc = row[3].strip() date_doc = spss_to_posix(row[4]) date_rec = spss_to_posix(row[5]) buyer = row[6].strip() buyer_type = row[7].strip() seller = row[8].strip() seller_type = row[9].strip() try: non_condo = int(row[10]) except: non_condo = None try: purchase_less_20k = int(row[11]) except: purchase_less_20k = None try: business_buyer = int(row[12]) except: business_buyer = None try: yq_doc = int(row[13]) except: yq_doc = None try: yeard = int(row[14]) except: yeard = None apt = row[15].strip() direction = row[16].strip() houseno = row[17].strip() street = row[18].strip() suffix = row[19].strip() addr_final = row[20].strip() city_final = row[21].strip() try: lat_y = float(row[22]) except: lat_y = None try: long_x = float(row[23]) except: long_x = None try: tract_fix = float(row[24]) except: tract_fix = None no_tract_info = True if int(row[25]) == 1 else False try: ca_num = int(row[26]) except: ca_num = None ca_name = row[27].strip() place = row[28].strip() gisdate = row[29].strip() try: ptype_id = int(row[30]) except: ptype_id = None try: residential = int(row[31]) except: residential = None try: adj_yq = int(row[32]) except: adj_yq = None try: adj_yd = int(row[33]) except: adj_yd = None loc = None if row[22] == '' else Point( (Decimal(row[23]), Decimal(row[22])), srid=4326).transform(3435) try: if skip_lookup: raise Exception('no lookup') transaction = Transaction.objects.get(\ pin = pin\ ,amount_prime = amount_prime\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,non_condo = non_condo\ ,purchase_less_20k = purchase_less_20k\ ,business_buyer = business_buyer\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) except: transaction = Transaction(\ pin = pin\ ,amount_prime = amount_prime\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,non_condo = non_condo\ ,purchase_less_20k = purchase_less_20k\ ,business_buyer = business_buyer\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) transaction.save()
def load_mortgages(mortgage_file, verbose=False): with open(mortgage_file, 'r') as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if Mortgage.objects.count() == 0: skip_lookup = True for row in reader: pin = '{:0>14}'.format(int(Decimal(row[1]))) doc = row[2].strip() try: mort_amt = float(row[3]) except: mort_amt = None date_doc = spss_to_posix(row[4]) date_rec = spss_to_posix(row[5]) borrower1 = row[6].strip() borrower1_type = row[7].strip() lender1 = row[8].strip() lender1_type = row[9].strip() lender2 = row[10].strip() lender2_type = row[11].strip() try: yq_doc = int(row[12]) except: yq_doc = None try: yeard = int(row[13]) except: yeard = None apt = row[14].strip() direction = row[15].strip() houseno = row[16].strip() street = row[17].strip() suffix = row[18].strip() addr_final = row[19].strip() city_final = row[20].strip() try: lat_y = float(row[21]) except: lat_y = None try: long_x = float(row[22]) except: long_x = None try: tract_fix = float(row[23]) except: tract_fix = None no_tract_info = True if int(row[24]) == 1 else False try: ca_num = int(row[25]) except: ca_num = None ca_name = row[26].strip() place = row[27].strip() gisdate = row[28].strip() try: ptype_id = int(row[29]) except: ptype_id = None try: residential = int(row[30]) except: residential = None try: adj_yq = int(row[31]) except: adj_yq = None try: adj_yd = int(row[32]) except: adj_yd = None loc = None if row[21] == '' else Point( (Decimal(row[22]), Decimal(row[21]))) try: if skip_lookup: raise Exception('no lookup') mortgage = Mortgage.objects.get(\ pin = pin\ ,doc = doc\ ,mort_amt = mort_amt\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,borrower1 = borrower1\ ,borrower1_type = borrower1_type\ ,lender1 = lender1\ ,lender1_type = lender1_type\ ,lender2 = lender2\ ,lender2_type = lender2_type\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) except: mortgage = Mortgage(\ pin = pin\ ,doc = doc\ ,mort_amt = mort_amt\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,borrower1 = borrower1\ ,borrower1_type = borrower1_type\ ,lender1 = lender1\ ,lender1_type = lender1_type\ ,lender2 = lender2\ ,lender2_type = lender2_type\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) mortgage.save()
def load_mortgages(mortgage_file, verbose = False): with open(mortgage_file,'r') as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if Mortgage.objects.count() == 0: skip_lookup = True for row in reader: pin = '{:0>14}'.format(int(Decimal(row[1]))) doc = row[2].strip() try: mort_amt = float(row[3]) except: mort_amt = None date_doc = spss_to_posix(row[4]) date_rec = spss_to_posix(row[5]) borrower1 = row[6].strip() borrower1_type = row[7].strip() lender1 = row[8].strip() lender1_type = row[9].strip() lender2 = row[10].strip() lender2_type = row[11].strip() try: yq_doc = int(row[12]) except: yq_doc = None try: yeard = int(row[13]) except: yeard = None apt = row[14].strip() direction = row[15].strip() houseno = row[16].strip() street = row[17].strip() suffix = row[18].strip() addr_final = row[19].strip() city_final = row[20].strip() try: lat_y = float(row[21]) except: lat_y = None try: long_x = float(row[22]) except: long_x = None try: tract_fix = float(row[23]) except: tract_fix = None no_tract_info = True if int(row[24])==1 else False try: ca_num = int(row[25]) except: ca_num = None ca_name = row[26].strip() place = row[27].strip() gisdate = row[28].strip() try: ptype_id = int(row[29]) except: ptype_id = None try: residential = int(row[30]) except: residential = None try: adj_yq = int(row[31]) except: adj_yq = None try: adj_yd = int(row[32]) except: adj_yd = None loc = None if row[21]=='' else Point((Decimal(row[22]), Decimal(row[21]))) try: if skip_lookup: raise Exception('no lookup') mortgage = Mortgage.objects.get(\ pin = pin\ ,doc = doc\ ,mort_amt = mort_amt\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,borrower1 = borrower1\ ,borrower1_type = borrower1_type\ ,lender1 = lender1\ ,lender1_type = lender1_type\ ,lender2 = lender2\ ,lender2_type = lender2_type\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) except: mortgage = Mortgage(\ pin = pin\ ,doc = doc\ ,mort_amt = mort_amt\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,borrower1 = borrower1\ ,borrower1_type = borrower1_type\ ,lender1 = lender1\ ,lender1_type = lender1_type\ ,lender2 = lender2\ ,lender2_type = lender2_type\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) mortgage.save()
def load_foreclosures(forc_file, verbose = False): with open(forc_file,'r') as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if Foreclosure.objects.count() == 0 skip_lookup = True for row in reader: pin = '{:0>14}'.format(int(Decimal(row[1]))) filing_date = spss_to_posix(row[2]) try: case_num1 = int(row[3]) except: case_num1 = None try: case_num2 = row[4].strip() except: case_num2 = None try: case_num3 = float(row[5]) except: case_num3 = None defendant_first_name = row[6].strip() defendant_last_name = row[7].strip() plaintiff = row[8].strip() try: yq_doc = int(row[9]) except: yq_doc = None try: yeard = int(row[10]) except: yeard = None apt = row[11].strip() direction = row[12].strip() houseno = row[13].strip() street = row[14].strip() suffix = row[15].strip() addr_final = row[16].strip() city_final = row[17].strip() try: lat_y = float(row[18]) except: lat_y = None try: long_x = float(row[19]) except: long_x = None try: tract_fix = float(row[20]) except: tract_fix = None no_tract_info = True if int(row[21])==1 else False try: ca_num = int(row[22]) except: ca_num = None ca_name = row[23].strip() place = row[24].strip() gisdate = row[25].strip() try: ptype_id = int(row[26]) except: ptype_id = None try: residential = int(row[27]) except: residential = None try: adj_yq = int(row[28]) except: adj_yq = None try: adj_yd = int(row[29]) except: adj_yd = None loc = None if row[18]=='' else Point((Decimal(row[19]), Decimal(row[18])),srid=4326).transform(3435) try: if skip_lookup: raise Exception('no lookup') forc = Foreclosure.objects.get(\ pin = pin\ ,filing_date = filing_date\ ,case_num1 = case_num1\ ,case_num2 = case_num2\ ,case_num3 = case_num3\ ,defendant_first_name = defendant_first_name\ ,defendant_last_name = defendant_last_name\ ,plaintiff = plaintiff\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) except: forc = Foreclosure(\ pin = pin\ ,filing_date = filing_date\ ,case_num1 = case_num1\ ,case_num2 = case_num2\ ,case_num3 = case_num3\ ,defendant_first_name = defendant_first_name\ ,defendant_last_name = defendant_last_name\ ,plaintiff = plaintiff\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) forc.save()
def load_transactions(transaction_file, verbose = False): with open(transaction_file,'r') as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if Transaction.objects.count() == 0: skip_lookup = True for row in reader: try: amount_prime = float(row[2]) except: amount_prime = None doc = row[3].strip() date_doc = spss_to_posix(row[4]) date_rec = spss_to_posix(row[5]) buyer = row[6].strip() buyer_type = row[7].strip() seller = row[8].strip() seller_type = row[9].strip() try: non_condo = int(row[10]) except: non_condo = None try: purchase_less_20k = int(row[11]) except: purchase_less_20k = None try: business_buyer = int(row[12]) except: business_buyer = None try: yq_doc = int(row[13]) except: yq_doc = None try: yeard = int(row[14]) except: yeard = None apt = row[15].strip() direction = row[16].strip() houseno = row[17].strip() street = row[18].strip() suffix = row[19].strip() addr_final = row[20].strip() city_final = row[21].strip() try: lat_y = float(row[22]) except: lat_y = None try: long_x = float(row[23]) except: long_x = None try: tract_fix = float(row[24]) except: tract_fix = None no_tract_info = True if int(row[25])==1 else False try: ca_num = int(row[26]) except: ca_num = None ca_name = row[27].strip() place = row[28].strip() gisdate = row[29].strip() try: ptype_id = int(row[30]) except: ptype_id = None try: residential = int(row[31]) except: residential = None try: adj_yq = int(row[32]) except: adj_yq = None try: adj_yd = int(row[33]) except: adj_yd = None loc = None if row[22]=='' else Point((Decimal(row[23]), Decimal(row[22])),srid=4326).transform(3435) try: if skip_lookup: raise Exception('no lookup') transaction = Transaction.objects.get(\ pin = pin\ ,amount_prime = amount_prime\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,non_condo = non_condo\ ,purchase_less_20k = purchase_less_20k\ ,business_buyer = business_buyer\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) except: transaction = Transaction(\ pin = pin\ ,amount_prime = amount_prime\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,non_condo = non_condo\ ,purchase_less_20k = purchase_less_20k\ ,business_buyer = business_buyer\ ,yq_doc = yq_doc\ ,yeard = yeard\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,adj_yq = adj_yq\ ,adj_yd = adj_yd\ ,loc = loc\ ) transaction.save()
def load_cashfin(cashfin_file, verbose = False): with open(cashfin_file,'r') as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if CashFin.objects.count() == 0: skip_lookup = True for row in reader: pin = '{:0>14}'.format(int(Decimal(row[1]))) doc = row[2] date_doc = spss_to_posix(row[3]) date_rec = spss_to_posix(row[4]) try: year = int(row[5]) except: year = None try: amount_prime = float(row[6]) except: amount_prime = None likely_distressed = True if int(row[7])==1 else False likely_cash = True if int(row[8])==1 else False buyer = row[9].strip() buyer_type = row[10].strip() seller = row[11].strip() seller_type = row[12].strip() apt = row[13].strip() direction = row[14].strip() houseno = row[15].strip() street = row[16].strip() suffix = row[17].strip() addr_final = row[18].strip() city_final = row[19].strip() try: lat_y = float(row[20]) except: lat_y = None try: long_x = float(row[21]) except: long_x = None try: tract_fix = float(row[22]) except: tract_fix = None no_tract_info = True if int(row[23])==1 else False try: ca_num = int(row[24]) except: ca_num = None ca_name = row[25].strip() place = row[26].strip() gisdate = row[27].strip() try: ptype_id = int(row[28]) except: ptype_id = None try: residential = int(row[29]) except: residential = None loc = None if row[20]=='' else Point((Decimal(row[21]), Decimal(row[20]))) try: if skip_lookup: raise Exception('no lookup') cashfin = CashFin.objects.get(\ pin = pin\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,year = year\ ,amount_prime = amount_prime\ ,likely_distressed = likely_distressed\ ,likely_cash = likely_cash\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,loc = loc\ ) except: cashfin = CashFin(\ pin = pin\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,year = year\ ,amount_prime = amount_prime\ ,likely_distressed = likely_distressed\ ,likely_cash = likely_cash\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,loc = loc\ ) cashfin.save()
def load_cashfin(cashfin_file, verbose=False): with open(cashfin_file, 'r') as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if CashFin.objects.count() == 0: skip_lookup = True for row in reader: pin = '{:0>14}'.format(int(Decimal(row[1]))) doc = row[2] date_doc = spss_to_posix(row[3]) date_rec = spss_to_posix(row[4]) try: year = int(row[5]) except: year = None try: amount_prime = float(row[6]) except: amount_prime = None likely_distressed = True if int(row[7]) == 1 else False likely_cash = True if int(row[8]) == 1 else False buyer = row[9].strip() buyer_type = row[10].strip() seller = row[11].strip() seller_type = row[12].strip() apt = row[13].strip() direction = row[14].strip() houseno = row[15].strip() street = row[16].strip() suffix = row[17].strip() addr_final = row[18].strip() city_final = row[19].strip() try: lat_y = float(row[20]) except: lat_y = None try: long_x = float(row[21]) except: long_x = None try: tract_fix = float(row[22]) except: tract_fix = None no_tract_info = True if int(row[23]) == 1 else False try: ca_num = int(row[24]) except: ca_num = None ca_name = row[25].strip() place = row[26].strip() gisdate = row[27].strip() try: ptype_id = int(row[28]) except: ptype_id = None try: residential = int(row[29]) except: residential = None loc = None if row[20] == '' else Point( (Decimal(row[21]), Decimal(row[20]))) try: if skip_lookup: raise Exception('no lookup') cashfin = CashFin.objects.get(\ pin = pin\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,year = year\ ,amount_prime = amount_prime\ ,likely_distressed = likely_distressed\ ,likely_cash = likely_cash\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,loc = loc\ ) except: cashfin = CashFin(\ pin = pin\ ,doc = doc\ ,date_doc = date_doc\ ,date_rec = date_rec\ ,year = year\ ,amount_prime = amount_prime\ ,likely_distressed = likely_distressed\ ,likely_cash = likely_cash\ ,buyer = buyer\ ,buyer_type = buyer_type\ ,seller = seller\ ,seller_type = seller_type\ ,apt = apt\ ,direction = direction\ ,houseno = houseno\ ,street = street\ ,suffix = suffix\ ,addr_final = addr_final\ ,city_final = city_final\ ,lat_y = lat_y\ ,long_x = long_x\ ,tract_fix = tract_fix\ ,no_tract_info = no_tract_info\ ,ca_num = ca_num\ ,ca_name = ca_name\ ,place = place\ ,gisdate = gisdate\ ,ptype_id = ptype_id\ ,residential = residential\ ,loc = loc\ ) cashfin.save()
def load_auctions(auction_file, verbose=False): with open(auction_file, "r") as f: reader = csv.reader(f, delimiter="\t") reader.next() skip_lookup = False if Auction.objects.count() == 0: skip_lookup = True for row in reader: pin = "{:0>14}".format(int(Decimal(row[1]))) doc = row[2].strip() date_doc = spss_to_posix(row[3]) date_rec = spss_to_posix(row[4]) reo = True if int(row[5]) == 1 else False buyer = row[6].strip() buyer_type = row[7].strip() seller = row[8].strip() seller_type = row[9].strip() try: yq_doc = int(row[10]) except: yq_doc = None try: yeard = int(row[11]) except: yeard = None apt = row[12].strip() direction = row[13].strip() houseno = row[14].strip() street = row[15].strip() suffix = row[16].strip() addr_final = row[17].strip() city_final = row[18].strip() try: lat_y = float(row[19]) except: lat_y = None try: long_x = float(row[20]) except: long_x = None try: tract_fix = float(row[21]) except: tract_fix = None no_tract_info = True if int(row[22]) == 1 else False try: ca_num = row[23] except: ca_num = None ca_name = row[24].strip() place = row[25].strip() gisdate = row[26].strip() try: ptype_id = int(row[27]) except: ptype_id = None try: residential = int(row[28]) except: residential = None try: adj_yq = int(row[29]) except: adj_yq = None try: adj_yd = int(row[30]) except: adj_yd = None loc = None if row[19] == "" else Point((Decimal(row[20]), Decimal(row[19]))) try: if skip_lookup: raise Exception("no lookup") auction = Auction.objects.get( pin=pin, doc=doc, date_doc=date_doc, date_rec=date_rec, reo=reo, buyer=buyer, buyer_type=buyer_type, seller=seller, seller_type=seller_type, yq_doc=yq_doc, yeard=yeard, apt=apt, direction=direction, houseno=houseno, street=street, suffix=suffix, addr_final=addr_final, city_final=city_final, lat_y=lat_y, long_x=long_x, tract_fix=tract_fix, no_tract_info=no_tract_info, ca_num=ca_num, ca_name=ca_name, place=place, gisdate=gisdate, ptype_id=ptype_id, residential=residential, adj_yq=adj_yq, adj_yd=adj_yd, loc=loc, ) except: auction = Auction( pin=pin, doc=doc, date_doc=date_doc, date_rec=date_rec, reo=reo, buyer=buyer, buyer_type=buyer_type, seller=seller, seller_type=seller_type, yq_doc=yq_doc, yeard=yeard, apt=apt, direction=direction, houseno=houseno, street=street, suffix=suffix, addr_final=addr_final, city_final=city_final, lat_y=lat_y, long_x=long_x, tract_fix=tract_fix, no_tract_info=no_tract_info, ca_num=ca_num, ca_name=ca_name, place=place, gisdate=gisdate, ptype_id=ptype_id, residential=residential, adj_yq=adj_yq, adj_yd=adj_yd, loc=loc, ) auction.save()