@@ -0,0 +1,2303 @@
+%22%22%22%0AImport Denbighshire%0A%22%22%22%0Afrom time import sleep%0Afrom django.contrib.gis.geos import Point%0Afrom data_collection.management.commands import BaseAddressCsvImporter%0Afrom data_finder.helpers import geocode%0A%0Aclass Command(BaseAddressCsvImporter):%0A    %22%22%22%0A    Imports the Polling Station data from Denbighshire%0A    %22%22%22%0A    council_id      = 'W06000004'%0A    addresses_name  = 'PropertyPostCodePollingStationWebLookup-2016-02-09.CSV'%0A    stations_name   = 'PollingStations-2016-02-09.csv'%0A    csv_encoding    = 'latin-1'%0A%0A    def station_record_to_dict(self, record):%0A%0A        # format address%0A        address = %22%5Cn%22.join(%5B%0A            record.pollingplaceaddress1,%0A            record.pollingplaceaddress2,%0A            record.pollingplaceaddress3,%0A            record.pollingplaceaddress4,%0A            record.pollingplaceaddress5,%0A            record.pollingplaceaddress6,%0A        %5D)%0A        while %22%5Cn%5Cn%22 in address:%0A            address = address.replace(%22%5Cn%5Cn%22, %22%5Cn%22)%0A%0A        %22%22%22%0A        No grid references were supplied,%0A        so attempt to derive a grid ref from postcode%0A        %0A        Unfortunately some of these postcodes cover%0A        quite large areas, so the postcode centroid may%0A        be some distance from the polling station :(%0A        %22%22%22%0A        sleep(1.3) # ensure we don't hit mapit's usage limit%0A        try:%0A            gridref = geocode(record.pollingplaceaddress7)%0A            location = Point(gridref%5B'wgs84_lon'%5D, gridref%5B'wgs84_lat'%5D, srid=4326)%0A        except KeyError:%0A            if record.pollingplaceaddress7 == 'LL21 8HA':%0A                location = Point(-3.7330709, 52.9864346, srid=4326)%0A            else:%0A                location = None%0A%0A        return %7B%0A            'internal_council_id': record.pollingplaceid,%0A            'postcode'           : record.pollingplaceaddress7,%0A            'address'            : address,%0A            'location'           : location%0A        %7D%0A%0A    def address_record_to_dict(self, record):%0A%0A        if record.propertynumber == '0':%0A            address = record.streetname%0A        else:%0A            address = '%25s %25s' %25 (record.propertynumber, record.streetname)%0A%0A        return %7B%0A            'address'           : address,%0A            'postcode'          : record.postcode,%0A            'polling_station_id': record.pollingplaceid%0A        %7D%0A

Add import script for Denbighshire