-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import script for Ribble Valley (2024-05-02) (closes #6576)
- Loading branch information
1 parent
b847e10
commit 45e81a5
Showing
1 changed file
with
24 additions
and
44 deletions.
There are no files selected for viewing
68 changes: 24 additions & 44 deletions
68
polling_stations/apps/data_importers/management/commands/import_ribble.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,29 @@ | ||
from data_importers.base_importers import BaseStationsDistrictsImporter | ||
from django.contrib.gis.geos import Point | ||
from data_importers.management.commands import BaseXpressDemocracyClubCsvImporter | ||
|
||
|
||
class Command(BaseStationsDistrictsImporter): | ||
srid = 27700 | ||
class Command(BaseXpressDemocracyClubCsvImporter): | ||
council_id = "RIB" | ||
elections = ["2023-05-04"] | ||
districts_name = "2023-05-04/2023-03-29T13:51:45/PD.geojson" | ||
stations_name = "2023-05-04/2023-03-29T13:51:45/PS.geojson" | ||
stations_filetype = "geojson" | ||
districts_filetype = "geojson" | ||
addresses_name = ( | ||
"2024-05-02/2024-03-13T10:03:27.884984/Democracy_Club__02May2024.tsv" | ||
) | ||
stations_name = ( | ||
"2024-05-02/2024-03-13T10:03:27.884984/Democracy_Club__02May2024.tsv" | ||
) | ||
elections = ["2024-05-02"] | ||
csv_delimiter = "\t" | ||
|
||
def station_record_to_dict(self, record): | ||
stations = [] | ||
codes = ( | ||
c.strip() | ||
for c in ( | ||
record["properties"]["CODE"], | ||
record["properties"]["CODE 2"], | ||
record["properties"]["CODE 3"], | ||
) | ||
if c | ||
) | ||
name = record["properties"]["Name"].strip() | ||
address = record["properties"]["Address"].strip() | ||
postcode = record["properties"]["Postcode"].strip() | ||
location = Point( | ||
record["properties"]["longitude"], | ||
record["properties"]["latitude"], | ||
srid=4326, | ||
) | ||
for code in codes: | ||
stations.append( | ||
{ | ||
"internal_council_id": code, | ||
"address": f"{name}\n{address}", | ||
"postcode": postcode, | ||
"polling_district_id": code, | ||
"location": location, | ||
} | ||
) | ||
return stations | ||
def address_record_to_dict(self, record): | ||
uprn = record.property_urn.strip().lstrip("0") | ||
|
||
def district_record_to_dict(self, record): | ||
return { | ||
"internal_council_id": record["properties"]["CODE"].strip(), | ||
"name": record["properties"]["NAME"], | ||
} | ||
if uprn in [ | ||
"10093891716", # 44 HACKINGS CARAVAN PARK ELKER LANE, BILLINGTON | ||
"10093893136", # BROCKTHRON LAITHE, WIGGLESWORTH ROAD, TOSSIDE, SKIPTON | ||
]: | ||
return None | ||
if record.addressline6 in [ | ||
# split | ||
"BB7 9GL", | ||
]: | ||
return None | ||
|
||
return super().address_record_to_dict(record) |