def read_file(fname): with open(fname, 'rb') as csvfile: reader = csv.reader(csvfile, delimiter='\t') header = {} pattern = re.compile('[\W_]+') for idx, val in enumerate(reader.next()): header[val] = idx for row in reader: if len(row) != len(header): continue prisoner_id_sanitized = pattern.sub('', row[header['PrisonerID']]) print "ID: %s " % prisoner_id_sanitized if row[header['BookEnrollDate']] == '00/00/00': book_date = '2000-01-01' else: book_date = time.strptime(row[header['BookEnrollDate']], "%m/%d/%y") book_date = datetime.fromtimestamp(time.mktime(book_date)) print "BookEnrollDate: %s" % book_date a = Address(city=row[header['City']], state=row[header['State']], postal_code=row[header['ZipCode']], address_1=row[header['PreAddress']], address_2=row[header['Address']]) a.save() p = Prisoner(name=row[header['FirstName']] + ' ' + row[header['LastName']], prisoner_id_raw=row[header['PrisonerID']], prisoner_id=prisoner_id_sanitized, last_active=book_date, address=a) p.save()
def read_file(fname): with open(fname, 'rb') as csvfile: reader = csv.reader(csvfile, delimiter='\t') header = {} pattern = re.compile('[\W_]+') for idx, val in enumerate(reader.next()): header[val] = idx for row in reader: if len(row) != len(header): continue prisoner_id_sanitized = pattern.sub('',row[header['PrisonerID']]) print "ID: %s " % prisoner_id_sanitized if row[header['BookEnrollDate']] == '00/00/00': book_date = '2000-01-01' else: book_date = time.strptime(row[header['BookEnrollDate']], "%m/%d/%y") book_date = datetime.fromtimestamp(time.mktime(book_date)) print "BookEnrollDate: %s" % book_date a = Address(city=row[header['City']], state=row[header['State']], postal_code=row[header['ZipCode']], address_1=row[header['PreAddress']], address_2=row[header['Address']]) a.save() p = Prisoner(name=row[header['FirstName']] +' '+ row[header['LastName']], prisoner_id_raw=row[header['PrisonerID']], prisoner_id=prisoner_id_sanitized, last_active=book_date, address=a) p.save()
def input(request): first_name = request.GET['first_name'] last_name = request.GET['last_name'] address = request.GET['addr'] pre_address = request.GET['preaddr'] city = request.GET['city'] state = request.GET['state'] zipcode = request.GET['zipcode'] if isfloat(zipcode): zipcode = str(int(float(zipcode))) a = Address(city=city, state=state, postal_code=zipcode, address_1=pre_address, address_2=address) a.save() raw_id = request.GET['id'] if isfloat(raw_id): raw_id = str(int(float(raw_id))) print raw_id, zipcode parsed_id = filter(str.isalnum, str(raw_id)) p = Prisoner(name=first_name + ' ' + last_name, active=True, address=a, prisoner_id=parsed_id, prisoner_id_raw=raw_id) p.save() return HttpResponse("%s has prisoner id of %s" % (p.name, p.prisoner_id))
def input(request): first_name=request.GET['first_name']; last_name=request.GET['last_name']; address=request.GET['addr']; pre_address=request.GET['preaddr']; city=request.GET['city']; state=request.GET['state']; zipcode=request.GET['zipcode']; if isfloat(zipcode) : zipcode=str(int(float(zipcode))) a = Address(city=city, state=state, postal_code=zipcode, address_1=pre_address, address_2=address) a.save() raw_id=request.GET['id']; if isfloat(raw_id) : raw_id=str(int(float(raw_id))) print raw_id ,zipcode parsed_id = filter(str.isalnum, str(raw_id)) p = Prisoner(name=first_name+' '+last_name, active=True, address=a, prisoner_id=parsed_id, prisoner_id_raw = raw_id) p.save() return HttpResponse("%s has prisoner id of %s" % (p.name, p.prisoner_id))