from data_collection.morph_importer import BaseMorphApiImporter

class Command(BaseMorphApiImporter):

    srid = 27700
    districts_srid = 27700
    council_id = 'E09000001'
    elections = [
        'gla.c.2016-05-05',
        'gla.a.2016-05-05',
        'mayor.london.2016-05-05',
        'ref.2016-06-23',
    ]
    scraper_name = 'wdiv-scrapers/DC-PollingStations-CityOfLondon'
    geom_type = 'gml'


    def district_record_to_dict(self, record):
        poly = self.extract_geometry(record, self.geom_type, self.get_srid('districts'))

        return {
            'internal_council_id': record['OBJECTID'],
            'name'               : record['POLLING_DISTRICT'],
            'area'               : poly
        }


    def station_record_to_dict(self, record):
        location = self.extract_geometry(record, self.geom_type, self.get_srid('stations'))


        # format address and postcode
        address = str(record['Address'])
        address_parts = address.split(', ')
        postcode = address_parts[-1]

        if postcode[:1] == 'E':
            del(address_parts[-1])
        else:
            postcode = address_parts[-1][-8:]
            address_parts[-1] = address_parts[-1][:-9]

        address = "\n".join(address_parts)


        return {
            'internal_council_id': record['OBJECTID'],
            'postcode':            postcode,
            'address':             address,
            'location':            location
        }

@@ -19,21 +19,26 @@
 on.m
-orph_importer
+anagement.commands
  imp
@@ -41,32 +41,35 @@
  import Base
-MorphApi
+HalaroseCsv
 Importer%0A%0Acl
@@ -88,71 +88,29 @@
 Base
-MorphApiImporter):%0A%0A    srid = 27700%0A    districts_srid = 27700
+HalaroseCsvImporter):
 %0A   
@@ -121,16 +121,21 @@
 ncil_id 
+     
 = 'E0900
@@ -148,558 +148,258 @@
     
-elections = %5B%0A     
+addresses_name
   
+=
  '
-gla.c
+parl
 .201
-6-05-05',%0A        'gla.a.2016-05-05',%0A        'mayor.london.2016
+7-06-08/Version 1/polling_station_export-2017
 -05-
-05',%0A    
+18.csv'%0A    stations_name
    
+=
  '
-ref
+parl
 .201
-6
+7
 -06-
-23',%0A    %5D%0A    scraper_name = 'wdiv-scrapers/DC-P
+08/Version 1/p
 olling
-S
+_s
 tation
-s-CityOfLondon'%0A    geom_type = 'gml'%0A%0A%0A    def district_record_to_dict(self, record):%0A        poly = self.extract_geometry(record, self.geom_type, self.get_srid('districts'))%0A%0A        return %7B%0A            'internal_council_id': record%5B'OBJECTID'%5D,%0A       
+_export-2017-05-18.csv'%0A    elections       = %5B'parl.2017-06-08'%5D%0A    csv_encoding
     
+=
  '
-name'               : record%5B'POLLING_DISTRICT'%5D,%0A            'area'               : poly%0A        %7D%0A
+windows-1252'
 %0A%0A  
@@ -454,40 +454,18 @@
     
-location = self.extract_geome
+if getat
 tr
-y
 (rec
@@ -478,238 +478,41 @@
 elf.
-geom_type, self.get_srid('stations'))%0A%0A%0A        # format address and postcode%0A        address = str(record%5B'Address'%5D)%0A        address_parts = address.split(', ')%0A        postcode = address_parts%5B-1%5D%0A%0A        if postcode%5B:1%5D
+station_id_field).strip()
  == '
-E
+n/a
 ':%0A 
@@ -526,403 +526,70 @@
     
-del(address_parts%5B-1%5D)%0A        else:%0A            postcode = address_parts%5B-1%5D%5B-8:%5D%0A            address_parts%5B-1%5D = address_parts%5B-1%5D%5B:-9%5D%0A%0A        address = %22%5Cn%22.join(address_parts)%0A%0A%0A        return %7B%0A            'internal_council_id': record%5B'OBJECTID'%5D,%0A            'postcode':            postcode,%0A            'address':             address,%0A            'location':            location%0A        %7D
+return None%0A        return super().station_record_to_dict(record)
 %0A

update City of London import script for parl.2017-06-08 (closes #781)