class ZIPImporter(Importer): def runImport(self): """ old File Format: "00210","Portsmouth","NH","43.005895","-71.013202","-5","1" new Format: 1316,"US","CA","Sunnyvale","94085",37.3887,-122.0188,807,408 1317,"US","CA","Morgan Hill","95037",37.1747,-121.6518,807,408 """ try: fp = open(self.fileName) except Exception, e: logging.error("could not open file %s for reading: %s" % (self.fileName, e)) return False reader = csv.reader(fp, delimiter=',', quotechar='"') pipe = self.redis.pipeline() i = 0 for row in reader: try: name = row[4] city = row[3] stateCode = row[2] lat = float(row[5]) lon = float(row[6]) state = row[2] #stateCode#code_to_state.get(stateCode, '').title() country = row[1] loc = ZIPCode(name=name, city=city, country=country, state=state, lat=lat, lon=lon) loc.save(pipe) except Exception, e: logging.error("Could not import line %s: %s" % (row, e)) i += 1 if i % 1000 == 0: pipe.execute()
class ZIPImporter(Importer): def runImport(self): """ File Format: "00210","Portsmouth","NH","43.005895","-71.013202","-5","1" """ try: fp = open(self.fileName) except Exception, e: logging.error("could not open file %s for reading: %s" % (self.fileName, e)) return False reader = csv.reader(fp, delimiter=',', quotechar='"') pipe = self.redis.pipeline() i = 0 for row in reader: try: name = row[0] city = row[1] stateCode = row[2] lat = float(row[3]) lon = float(row[4]) state = stateCode #code_to_state.get(stateCode, '').title() country = 'US' loc = ZIPCode(name=name, city=city, country=country, state=state, lat=lat, lon=lon) loc.save(pipe) except Exception, e: logging.error("Could not import line %s: %s" % (row, e)) i += 1 if i % 1000 == 0: pipe.execute()