@@ -0,0 +1,2395 @@
+%22%22%22%0AImport Hounslow%0A%0Anote: this script takes quite a long time to run%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, PostcodeError%0A%0Aclass Command(BaseAddressCsvImporter):%0A    %22%22%22%0A    Imports the Polling Station data from Hounslow Council%0A    %22%22%22%0A    council_id      = 'E09000018'%0A    addresses_name  = 'Hounslow_polling_station_export-2016-06-06.csv'%0A    stations_name   = 'polling_stations.csv'%0A    elections       = %5B%0A        'ref.2016-06-23'%0A    %5D%0A%0A    def station_record_to_dict(self, record):%0A        location = Point(float(record.cntr_x), float(record.cntr_y), srid=27700)%0A%0A        # format address and postcode%0A        address = record.polling_station_address%0A        address_parts = address.split(', ')%0A        address_parts = %5Bx.strip(' ') for x in address_parts%5D%0A        if address_parts%5B-1%5D%5B:2%5D == 'TW' or%5C%0A           address_parts%5B-1%5D%5B:2%5D == 'UB' or%5C%0A           address_parts%5B-1%5D%5B:2%5D == 'W3' or%5C%0A           address_parts%5B-1%5D%5B:2%5D == 'W4' or%5C%0A           address_parts%5B-1%5D%5B:2%5D == 'W5':%0A            postcode = address_parts%5B-1%5D%0A            del(address_parts%5B-1%5D)%0A        else:%0A            postcode = ''%0A        address = %22%5Cn%22.join(address_parts)%0A%0A        return %7B%0A            'internal_council_id': record.polling_station_number.strip(),%0A            'postcode'           : postcode,%0A            'address'            : %22%25s%5Cn%25s%22 %25 (record.polling_station_name, address),%0A            'location'           : location%0A        %7D%0A%0A    def address_record_to_dict(self, record):%0A%0A        # discard and records without a postcode%0A        # the user won't be able to search for them anyway%0A        if not record.housepostcode:%0A            return None%0A%0A        # format address%0A        address1 = %22%25s %25s %25s %25s %25s%22 %25 (record.housename, record.housenumber, record.substreetname, record.streetnumber, record.streetname)%0A        address1 = ' '.join(address1.strip().split())%0A%0A        address = %22%5Cn%22.join(%5B%0A            address1,%0A            record.locality,%0A            record.town,%0A            record.adminarea,%0A        %5D).strip()%0A        address = %22, %22.join(address.split(%22%5Cn%22))%0A%0A        return %7B%0A            'address'           : address,%0A            'postcode'          : record.housepostcode,%0A            'polling_station_id': record.pollingstationnumber%0A        %7D%0A

add import script for Hounslow