Changeset 578

Show
Ignore:
Timestamp:
02/17/10 14:18:14 (5 months ago)
Author:
olivier
Message:

geocoder: restrict search to geonames with PCL* feature code ; optimize

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/telemeta/management/commands/telemeta-geocode.py

    r576 r578  
    2121            raise CommandError("Unable to open %s" % datafile) 
    2222             
    23         locations = Location.objects.filter(type=Location.COUNTRY) 
     23        locations = [l for l in Location.objects.filter(type=Location.COUNTRY)] 
     24 
    2425        i = 0 
    2526        geocoded = 0 
    26         total = locations.count() 
     27        total = len(locations) 
    2728        for line in datafile: 
    2829            (geonameid, name, asciiname, alternatenames, latitude, longitude, feature_class, 
     
    3031             admin4_code, population, elevation, gtopo30, timezone, modification_date) = line.strip().split("\t") 
    3132            
    32             if feature_class == 'A': 
     33            if feature_code[0:3] == 'PCL': 
    3334                names = [asciiname.lower()] 
    3435                if alternatenames: 
    3536                    names.extend([unaccent(n).lower() for n in alternatenames.split(',')]) 
    3637 
     38                found = [] 
    3739                for l in locations: 
    3840                    if unaccent(l.name).lower() in names: 
     
    4143                        l.save() 
    4244                        geocoded += 1 
     45                        found.append(l) 
     46 
     47                for l in found: 
     48                    locations.remove(l) 
    4349 
    4450            i += 1