Changeset 671
- Timestamp:
- Sep 26, 2008, 11:29:27 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/npemap.org.uk/scripts/generic-python-import/generic_importer.py
r651 r671 159 159 160 160 # Read in the new list 161 postcodes = []161 raw_postcodes = {} 162 162 ftpc = open(current_file, 'r') 163 163 for line in ftpc: 164 164 pc = self.process_line(line) 165 165 if pc: 166 postcodes.append(pc) 166 raw_pc = pc["raw"] 167 if not raw_postcodes.has_key(raw_pc): 168 raw_postcodes[raw_pc] = [] 169 raw_postcodes[raw_pc].append(pc) 170 171 # Ensure that the postcodes entries are unique, and 172 # average them if not 173 postcodes = [] 174 for raw_pc, arr_data in raw_postcodes.items(): 175 if len(arr_data) == 1: 176 # Only the one, easy 177 pc = arr_data[0] 178 else: 179 # Several, average 180 lat = 0 181 lng = 0 182 for pc in arr_data: 183 lat += float(pc["latitude"]) 184 lng += float(pc["longitude"]) 185 # Create the average 186 pc = arr_data[0] 187 pc["latitude"] = lat / len(arr_data) 188 pc["longitude"] = lng / len(arr_data) 189 self.generate_easting_northing(pc) 190 # Save the now always-unique postcode 191 postcodes.append( pc ) 167 192 168 193 … … 183 208 count = len(spcs.keys()) 184 209 185 print "There are currently %d entries in the database from %s" % (count, self.source_name) 210 # And for interest, the count of deleted ones 211 sql = "SELECT COUNT(id) FROM postcodes WHERE source = %s AND deleted" 212 sth = dbh.cursor() 213 sth.execute(sql, source_id) 214 deleted_count = sth.fetchone()[0] 215 sth.close() 216 217 print "There are currently %d entries in the database from the %s. (Additionally, there are %d deleted ones)" % (count, self.source_name, deleted_count) 186 218 print "The new import contains %d entries" % len(postcodes) 187 219
Note: See TracChangeset
for help on using the changeset viewer.