openmumbai/openmumbai/places/import_csv.py

25 lines
624 B
Python

import csv
from models import *
from decimal import Decimal
def do(filename):
CsvFile = csv.reader(open(filename), delimiter="\t")
for row in CsvFile:
p = {}
p.ward = row[0].strip()
p.reservation = row[1].strip()
try:
p.pk_serial = int(row[2].strip())
except:
p.pk_serial = None
p.occupied = (row[3].strip() == '*')
p.name = row[4]
p.address = row[5]
p.cts = row[6]
try:
p.area = Decimal(row[7].strip())
except:
p.area = 0.0
p.save()
print "%s saved" % p.name