def parse_file(self, fo): parser = parser(self.config[PATHS]['db_path'], self.config[FILES]['db_name']) lines = fo.readlines() data = [] for line in lines: blocks = line.split(',') route = street = sender = info = user_info = phone = postcode = '' if len(blocks) > 0: postcode = blocks[0] # 1 & 2 are internal codes defining parcel type - not used here if len(blocks) > 3: name = StringUtil.titlecase(blocks[3]) if len(blocks) > 4: street = blocks[4].strip() if len(blocks) > 5: phone = blocks[5].strip() if len(sender) > 6: sender = self.expandSender( blocks[6] ) # the company/person sending the package - added to note if len(blocks) > 7: info = blocks[7] if len(blocks) > 8: route = blocks[8][3:6] if len(user_info) > 9: user_info = blocks[9] postcodevalid, postcode = RWAddressParser.validatePostcode( postcode) if not postcodevalid: # TODO some form of error checking and reporting continue #error = 'Error : Route={route}, Name={name}, Postcode={postcode} - Invalid postcode'.format(route=route, name=name, postcode = postcode) # self.comms.emit(error) #continue address = parser.parse(street, postcode, name) if address: notes = sender notes += ' : ' + info rowlist = [] rowlist.append(address.address()) # should be number + street rowlist.append(address.city) # town/city rowlist.append(address.region2) # County/State rowlist.append(postcode) # post code rowlist.append(address.country) # Country rowlist.append("1.0") # Priority rowlist.append(phone) # Phone number rowlist.append(StringUtil.chomp(notes)) rowlist.append(address.lat) rowlist.append(address.lon) data.append(rowlist) self.m_rwdata[route] = data
city_id = db.insertCityIntoDB('Brixham', region_id) city_id = db.insertCityIntoDB('Kingswear', region_id) city_id = db.insertCityIntoDB('Dartmouth', region_id) city_id = db.insertCityIntoDB('Dartmouth', region_id) # should be ignored as is a repeat region = g_address.region2 preferred = db.getPreferredRegionFromDB(region, country_id) if preferred != None: region = preferred region_id = db.getRegionIdFromDB(region, country_id) city = g_address.city city_id = db.getCityIdFromDB(city, region_id) street = g_address.street s_address = expand_address(street)[0] # pypostal expands rd to road etc s_address = StringUtil.titlecase(s_address) def_lat = g_address.lat def_lon = g_address.lon street_id = db.insertStreetIntoDB(s_address, city_id, postcode, def_lat, def_lon) lat,lon = db.getDefaultLatLonFromDB(postcode) print(lat) print(lon) db.close()