From: olivier <> Date: Wed, 17 Feb 2010 13:18:14 +0000 (+0000) Subject: geocoder: restrict search to geonames with PCL* feature code ; optimize X-Git-Tag: 1.1~515 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=5df10e1b184d2b52f4cd2c79c489e60fca66d501;p=telemeta.git geocoder: restrict search to geonames with PCL* feature code ; optimize --- diff --git a/telemeta/management/commands/telemeta-geocode.py b/telemeta/management/commands/telemeta-geocode.py index 166bc408..5efe6835 100644 --- a/telemeta/management/commands/telemeta-geocode.py +++ b/telemeta/management/commands/telemeta-geocode.py @@ -20,26 +20,32 @@ class Command(BaseCommand): except IOError: raise CommandError("Unable to open %s" % datafile) - locations = Location.objects.filter(type=Location.COUNTRY) + locations = [l for l in Location.objects.filter(type=Location.COUNTRY)] + i = 0 geocoded = 0 - total = locations.count() + total = len(locations) for line in datafile: (geonameid, name, asciiname, alternatenames, latitude, longitude, feature_class, feature_code, country_code, cc2, admin1_code, admin2_code, admin3_code, admin4_code, population, elevation, gtopo30, timezone, modification_date) = line.strip().split("\t") - if feature_class == 'A': + if feature_code[0:3] == 'PCL': names = [asciiname.lower()] if alternatenames: names.extend([unaccent(n).lower() for n in alternatenames.split(',')]) + found = [] for l in locations: if unaccent(l.name).lower() in names: l.latitude = float(latitude) l.longitude = float(longitude) l.save() geocoded += 1 + found.append(l) + + for l in found: + locations.remove(l) i += 1