db = create_engine(DBURI) db_session = scoped_session(sessionmaker(autocommit=False, autoflush=True, bind=db)) print [f[0] for f in r.fields[1:]] for idx in xrange(r.numRecords): recshape = r.shapeRecord(idx) rec, shape = recshape.record, recshape.shape fips = int(rec[0]) print fips shp = get_wkt(shape) shapeobj = Shape(shp) zipcode = Zipcode(fips=fips, zip_shape=shapeobj) db_session.add_all([shapeobj, zipcode]) db_session.commit() if idx > 0 and idx % 500 == 0: db_session.commit() db_session.commit()
db_session = scoped_session(sessionmaker(autocommit=False, autoflush=True, bind=db)) for idx in xrange(r.numRecords): recshape = r.shapeRecord(idx) rec, shape = recshape.record, recshape.shape statefp, shortname, name = int(rec[0]), rec[2].lower(), rec[3].lower() shortname = to_utf(shortname) name = to_utf(name) print name shapeobj = Shape(get_wkt(shape)) names = [StateName(fips=statefp, name=name), StateName(fips=statefp, name=shortname)] state = State(fips=statefp, names=names, state_shape=shapeobj) db_session.add_all(names) db_session.add_all([shapeobj, state]) db_session.commit() if idx > 0 and idx % 50 == 0: db_session.commit() db_session.commit()