Skip to content

Commit

Permalink
Import script for Torfaen (2024-05-02) (closes #6222)
Browse files Browse the repository at this point in the history
  • Loading branch information
polling-bot-4000 authored and GeoWill committed Mar 8, 2024
1 parent e0ae96b commit c73d98a
Showing 1 changed file with 11 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
from addressbase.models import Address, UprnToCouncil
from core.opening_times import OpeningTimes
from data_importers.management.commands import BaseHalaroseCsvImporter
from data_importers.mixins import AdvanceVotingMixin
from pollingstations.models import AdvanceVotingStation


class Command(BaseHalaroseCsvImporter, AdvanceVotingMixin):
class Command(BaseHalaroseCsvImporter):
council_id = "TOF"
addresses_name = (
"2022-05-05/2022-03-01T07:51:07.153603/polling_station_export-2022-03-01.csv"
"2024-05-02/2024-03-08T13:10:09.629993/Export From Query for Caroline v4.csv"
)
stations_name = (
"2022-05-05/2022-03-01T07:51:07.153603/polling_station_export-2022-03-01.csv"
"2024-05-02/2024-03-08T13:10:09.629993/Export From Query for Caroline v4.csv"
)
elections = ["2022-05-05"]
elections = ["2024-05-02"]

def address_record_to_dict(self, record):
uprn = record.uprn.strip().lstrip("0")
Expand All @@ -23,46 +19,16 @@ def address_record_to_dict(self, record):
]:
return None

if record.housepostcode in [
"NP4 7NW",
"NP4 8JQ",
if record.housepostcode.strip() in [
# split
"NP4 8LG",
"NP44 1LE",
"NP44 4QS",
"NP4 7NW",
"NP44 5AB",
# suspect
"NP4 8QW",
"NP4 8QP",
"NP4 6TX",
]:
return None

return super().address_record_to_dict(record)

def station_record_to_dict(self, record):
# FORGESIDE COMMUNITY CENTRE FORGESIDE COMMUNITY CENTRE BFORGESIDE BLAENAVON TORFAEN NP4 9BD
if record.pollingstationname == "FORGESIDE COMMUNITY CENTRE":
record = record._replace(pollingstationpostcode="NP4 9DH")

# THORNHILL4UTOO THORNHILL COMMUNITY CENTRE LEADON COURT THORNHILL CWMBRAN TORFAEN NP44 5YZ
if record.pollingstationname == "THORNHILL4UTOO":
record = record._replace(pollingstationpostcode="NP44 5TZ")

return super().station_record_to_dict(record)

def add_advance_voting_stations(self):
opening_times = OpeningTimes()
opening_times.add_open_time("2022-04-30", "10:00", "16:00")
opening_times.add_open_time("2022-05-01", "10:00", "16:00")

advance_station = AdvanceVotingStation(
name="Pontypool Civic Centre",
address="""Glantorvaen Road
Pontypool
Torfaen
""",
postcode="NP4 6YB",
location=Address.objects.get(uprn=100101048589).location,
opening_times=opening_times.as_string_table(),
council=self.council,
)
advance_station.save()
UprnToCouncil.objects.filter(lad=self.council.geography.gss).update(
advance_voting_station=advance_station
)

0 comments on commit c73d98a

Please sign in to comment.