Skip to content

Instantly share code, notes, and snippets.

@cnorthwood
Created April 3, 2024 09:06
Show Gist options
  • Save cnorthwood/5cd0c719eaf85d48c43d3d5db30db699 to your computer and use it in GitHub Desktop.
Save cnorthwood/5cd0c719eaf85d48c43d3d5db30db699 to your computer and use it in GitHub Desktop.
import csv
import sys
def ballot_type(row):
if row["AVDescription"] == "Postal" and row["AVType"].startswith("Permanent"):
return "Perm Postal"
elif row["AVDescription"] == "Postal" and row["AVType"].startswith("Temporary"):
return "Postal"
elif row["AVDescription"] == "Proxy" and row["AVType"].startswith("Permanent"):
return "Perm Proxy"
elif row["AVDescription"] == "Proxy" and row["AVType"].startswith("Temporary"):
return "Proxy"
elif row["AVDescription"] == "Postal/Proxy" and row["AVType"].startswith("Permanent"):
return "Perm Postal Proxy"
elif row["AVDescription"] == "Postal/Proxy" and row["AVType"].startswith("Temporary"):
return "Postal Proxy"
else:
raise Exception(f"Unrecognised {row["AVDescription"]} {row["AVType"]}")
with open(sys.argv[1], encoding="windows-1252") as tsvfile:
reader = csv.DictReader(tsvfile, dialect="excel-tab")
with open("Processed Absent Voters.csv", "w") as outputcsvfile:
writer = csv.DictWriter(outputcsvfile, fieldnames=["PollingDistrict", "ElectorNumber", "BallotType"])
writer.writeheader()
for row in reader:
writer.writerow({"PollingDistrict": row["DistrictRef"], "ElectorNumber": row["ElectorNumber"].split("-")[1], "BallotType": ballot_type(row)})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment