Ejemplo n.º 1
0
def fix_pcdistricts(dbname):
    """
    Postcode districts, eg PA1, don't have good lat/lons cos geonames file has multiple entries.
    Use google lookup to sort them.
    """

    count = Location.objects(loc_type="POSTCODEDISTRICT").count()
    print 'location:', count

    for i in range(0, count, 5):

        print i, i+5
        for pcdistrict in Location.objects(loc_type="POSTCODEDISTRICT")[i:i+5]:
            res, addr = lookup_postcode(pcdistrict.postcode)
            pcdistrict.lat_lon = (res.geometry.location.lat, res.geometry.location.lng)
            print pcdistrict.lat_lon
            pcdistrict.save()
        # needs a delay or google complains
        time.sleep(5) # seconds
Ejemplo n.º 2
0
def fix_pcdistricts(dbname):
    """
    Postcode districts, eg PA1, don't have good lat/lons cos geonames file has multiple entries.
    Use google lookup to sort them.
    """

    count = Location.objects(loc_type="POSTCODEDISTRICT").count()
    print 'location:', count

    for i in range(0, count, 5):

        print i, i + 5
        for pcdistrict in Location.objects(loc_type="POSTCODEDISTRICT")[i:i +
                                                                        5]:
            res, addr = lookup_postcode(pcdistrict.postcode)
            pcdistrict.lat_lon = (res.geometry.location.lat,
                                  res.geometry.location.lng)
            print pcdistrict.lat_lon
            pcdistrict.save()
        # needs a delay or google complains
        time.sleep(5)  # seconds
Ejemplo n.º 3
0
 def clean_new_location(self):
     data = self.cleaned_data['new_location']
     if data:
         loc_ids = data.split(',')
         locs = list(Location.objects(id__in=loc_ids))
         new_locs = [l for l in loc_ids if l not in [loc.id for loc in locs]]
         new_locs_errors = []
         for new_loc in new_locs:
             loc = Location.create_from(new_loc)
             if loc:
                 locs.append(loc)
             else:
                 increment_failed_locations(new_loc)
                 new_locs_errors.append(new_loc)
         self.locations = locs
         if new_locs_errors:
             raise forms.ValidationError('Could not find these locations: %s' % ', '.join(new_locs_errors))
     return data
Ejemplo n.º 4
0
 def clean_new_location(self):
     data = self.cleaned_data['new_location']
     if data:
         loc_ids = data.split(',')
         locs = list(Location.objects(id__in=loc_ids))
         new_locs = [l for l in loc_ids if l not in [loc.id for loc in locs]]
         new_locs_errors = []
         for new_loc in new_locs:
             loc = Location.create_from(new_loc)
             if loc:
                 locs.append(loc)
             else:
                 increment_failed_locations(new_loc)
                 new_locs_errors.append(new_loc)
         self.locations = locs
         if new_locs_errors:
             raise forms.ValidationError('Could not find these locations: %s' % ', '.join(new_locs_errors))
     return data