Skip to content

Instantly share code, notes, and snippets.

This list was made using ONDAS and AddressBase. Here's a rough giude to how it was made:

  1. Get ONSAD
  • Get a CSV file with UPRN,Postcode, I got this from the AddressBase
  • Install csvkit
  • Remove all the columns in ONSAD that we don't care about (we only want the 'LAD' column): cat ../ONSAD_JAN_2017/Data/*.csv | csvcut -c 1,3 > uprn_lad.csv
  • We now have two CSV files, each with two columns. One UPRN,postcode the other UPRN,LAD.
  • Run join.py to join the two files in to a single file with 3 columns
  • Make a file with postcode,lad: cat joined.csv | csvcut -c 3,2 > postcode_lad.csv
  • Filter out duplicate rows: sort -u postcode_lad.csv> unique_rows.csv
election_slugs = ['local.aberdeen-city.2017-05-04',
'local.aberdeenshire.2017-05-04',
'local.angus.2017-05-04',
'local.city-of-edinburgh.2017-05-04',
'local.clackmannanshire.2017-05-04',
'local.dumfries-and-galloway.2017-05-04',
'local.east-ayrshire.2017-05-04',
'local.east-dunbartonshire.2017-05-04',
'local.east-lothian.2017-05-04',
'local.east-renfrewshire.2017-05-04',
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Appeal against a housing benefit decision
Appeal against your council's housing decision
Appeal against your parking fine
Apply for a community alarm
Apply for a council home
Apply for a disabled person's bus pass
Apply for a discount on council tax
Apply for a needs assessment by social services
Apply for a parking permit
Apply for a performance/stage licence for school age children
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 6.
"address","postcode","st_astext"
"BLACKFEN ROAD
SIDCUP","DA15 8QS","POINT(0.0959100982581493 51.4511501608113)"
"PICARDY ROAD
BELVEDERE","DA17 5AX","POINT(0.148883410691916 51.4865403697307)"
"HARVEL CRESCENT
ABBEY WOOD","SE2 0QA","POINT(0.129565784178912 51.4824863175941)"
"11 WOOLWICH ROAD
BELVEDERE","DA17 5HR","POINT(0.145217342248926 51.4839276204586)"
"ST AUGUSTINES ROAD
from django.db import transaction
from django.db import models
class Collection(models.Model):
name = models.CharField(blank=True, max_length=100)
revision = models.IntegerField(blank=True, null=False)
@transaction.atomic
def save(self, items_dict, *args, **kwargs):
We can make this file beautiful and searchable if this error is corrected: Unclosed quoted field in line 3.
postcode,ps_internal_council_id,ps_polling_district_id,ps_postcode,ps_address,ps_location_wkt
EN4 0EU,4538,YDA,EN4 0EN,"St. Pauls Church Hall
Crescent East
Hadley Wood
Barnet
Hertfordshire
EN4 0EN",POINT (-0.1724724088639866 51.6680869449261309)
N14 4DS,4548,YDD,N14 4AP,"14th Southgate Scout Headquarters
Green Road
Southgate
'RG14 1BD',
'RG14 1HR',
'RG14 1RG',
'RG14 1RS',
'RG14 1RW',
'RG14 1UH',
'RG14 2LY',
'RG14 2NY',
'RG14 2RP',
'RG14 2SF',
In [7]: council = Council.objects.get(pk='E06000037')
In [8]: districts_requiring_address_lookup(council)
17 postcodes don't need attention
Out[8]:
{'Aldermaston - AA1': ['RG7 4PA', 'RG7 4JX', 'RG7 4PJ'],
'Aldermaston - AA2': ['RG7 2PB', 'RG7 2PD', 'RG7 4PJ', 'RG7 4PA'],
'Aldermaston - BH': ['RG7 4RN', 'RG7 4RT', 'RG19 8EF', 'RG7 4NB'],
'Aldermaston - MA': ['RG7 5TY', 'RG19 4NN', 'RG7 5RY', 'RG19 4NT', 'RG7 5TT'],