From a39858932a8c762d8c4e8cef9af30826560e7d78 Mon Sep 17 00:00:00 2001 From: formcore Date: Thu, 9 Jan 2025 15:19:25 +0000 Subject: [PATCH] init --- .gitignore | 7 + README.md | 0 data/area_codes.json | 2292 ++++++++++++++++++++++++++++++++++++++++ generate_json.py | 16 + makefile | 60 ++ pyproject.toml | 19 + src/uk_plate_reader.py | 56 + test/test_main.py | 33 + 8 files changed, 2483 insertions(+) create mode 100644 .gitignore create mode 100644 README.md create mode 100644 data/area_codes.json create mode 100644 generate_json.py create mode 100644 makefile create mode 100644 pyproject.toml create mode 100644 src/uk_plate_reader.py create mode 100644 test/test_main.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..acd339f --- /dev/null +++ b/.gitignore @@ -0,0 +1,7 @@ +.git +.venv +.pytest_cache +.Python +*.tgz +*/__pycache__ +*/*.egg-info \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..e69de29 diff --git a/data/area_codes.json b/data/area_codes.json new file mode 100644 index 0000000..8ce8661 --- /dev/null +++ b/data/area_codes.json @@ -0,0 +1,2292 @@ +{ + "legacy_style": { + "A": "London", + "AA": "Bournemouth", + "AB": "Worcester", + "AC": "Coventry", + "AD": "Gloucester", + "AE": "Bristol", + "AF": "Truro", + "AG": "Hull", + "AH": "Norwich", + "AJ": "Middlesbrough", + "AK": "Sheffield", + "AL": "Nottingham", + "AM": "Swindon", + "AN": "Reading", + "AO": "Carlisle", + "AP": "Brighton", + "AR": "Chelmsford", + "AS": "Inverness", + "AT": "Hull", + "AU": "Nottingham", + "AV": "Peterborough", + "AW": "Shrewsbury", + "AX": "Cardiff", + "AY": "Leicester", + "AZ": "Belfast", + "B": "Lancashire", + "BA": "Manchester", + "BB": "Newcastle-upon-Tyne", + "BC": "Leicester", + "BD": "Northampton", + "BE": "Lincoln", + "BF": "Stoke-on-Trent", + "BG": "Liverpool", + "BH": "Luton", + "BJ": "Ipswich", + "BK": "Portsmouth", + "BL": "Reading", + "BM": "Luton", + "BN": "Manchester or Bolton", + "BO": "Cardiff", + "BP": "Portsmouth", + "BR": "Newcastle-upon-Tyne", + "BS": "Aberdeen", + "BT": "Leeds", + "BU": "Manchester", + "BV": "Preston", + "BW": "Oxford", + "BX": "Haverfordwest", + "BY": "London (North-West)", + "BZ": "County Down", + "C": "West Yorkshire", + "CA": "Chester", + "CB": "Manchester", + "CC": "Bangor", + "CD": "Brighton", + "CE": "Peterborough", + "CF": "Reading", + "CG": "Bournemouth", + "CH": "Nottingham", + "CJ": "Gloucester", + "CK": "Preston", + "CL": "Norwich", + "CM": "Liverpool", + "CN": "Newcastle-upon-Tyne", + "CO": "Exeter", + "CP": "Huddersfield", + "CR": "Southampton ", + "CS": "Glasgow", + "CT": "Lincoln", + "CU": "Newcastle-upon-Tyne", + "CV": "Truro", + "CW": "Preston", + "CX": "Huddersfield", + "CY": "Swansea", + "CZ": "Belfast", + "D": "Kent", + "DA": "Birmingham", + "DB": "Manchester", + "DC": "Middlesbrough", + "DD": "Gloucester", + "DE": "Haverfordwest", + "DF": "Gloucester", + "DG": "Gloucester", + "DH": "Dudley", + "DJ": "Liverpool", + "DK": "Rochdale, later Manchester", + "DL": "Portsmouth", + "DM": "Chester", + "DN": "Leeds", + "DO": "Lincoln", + "DP": "Reading", + "DR": "Exeter", + "DS": "Glasgow", + "DT": "Sheffield", + "DU": "Coventry", + "DV": "Exeter", + "DW": "Cardiff", + "DX": "Ipswich", + "DY": "Brighton", + "DZ": "County Antrim", + "E": "Staffordshire", + "EA": "Dudley", + "EB": "Peterborough", + "EC": "Preston", + "ED": "Liverpool", + "EE": "Lincoln", + "EF": "Middlesbrough", + "EG": "Peterborough", + "EH": "Stoke-on-Trent", + "EJ": "Haverfordwest", + "EK": "Liverpool", + "EL": "Bournemouth", + "EM": "Liverpool", + "EN": "Bury, later Manchester", + "EO": "Preston", + "EP": "Swansea", + "ER": "Peterborough", + "ES": "Dundee", + "ET": "Sheffield", + "EU": "Bristol", + "EV": "Chelmsford", + "EW": "Peterborough", + "EX": "Norwich", + "EY": "Bangor", + "EZ": "Belfast", + "F": "Essex", + "FA": "Stoke-on-Trent", + "FB": "Bristol", + "FC": "Oxford", + "FD": "Dudley", + "FE": "Lincoln", + "FF": "Bangor", + "FG": "Brighton", + "FH": "Gloucester", + "FJ": "Exeter", + "FK": "Dudley", + "FL": "Peterborough", + "FM": "Chester", + "FN": "Maidstone", + "FO": "Gloucester", + "FP": "Leicester", + "FR": "Preston", + "FS": "Edinburgh", + "FT": "Newcastle-upon-Tyne", + "FU": "Lincoln", + "FV": "Preston", + "FW": "Lincoln", + "FX": "Bournemouth", + "FY": "Liverpool", + "FZ": "Belfast", + "G": "Glasgow", + "GA": "Glasgow", + "GB": "Glasgow", + "GC": "London (South-West)", + "GD": "Glasgow", + "GE": "Glasgow", + "GF": "London (South-West)", + "GG": "Glasgow", + "GH": "London (South-West)", + "GJ": "London (South-West)", + "GK": "London (South-West)", + "GL": "Truro", + "GM": "Reading", + "GN": "London (South-West)", + "GO": "London (South-West)", + "GP": "London (South-West)", + "GR": "Newcastle-upon-Tyne", + "GS": "Luton", + "GT": "London (South-West)", + "GU": "London (South-East)", + "GV": "Ipswich", + "GW": "London (South-East)", + "GX": "London (South-East)", + "GY": "London (South-East)", + "GZ": "Belfast", + "H": "London", + "HA": "Dudley", + "HB": "Cardiff", + "HC": "Brighton", + "HD": "Huddersfield", + "HE": "Sheffield", + "HF": "Liverpool", + "HG": "Preston", + "HH": "Carlisle", + "HJ": "Chelmsford", + "HK": "Chelmsford", + "HL": "Sheffield", + "HM": "London (Central)", + "HN": "Middlesbrough", + "HO": "Bournemouth", + "HP": "Coventry", + "HR": "Swindon", + "HS": "Glasgow", + "HT": "Bristol", + "HU": "Bristol", + "HV": "London (Central)", + "HW": "Bristol", + "HX": "London (Central)", + "HY": "Bristol", + "J": "Durham", + "JA": "Manchester", + "JB": "Reading", + "JC": "Bangor", + "JD": "London (Central)", + "JE": "Peterborough", + "JF": "Leicester", + "JG": "Maidstone", + "JH": "Reading", + "JJ": "Maidstone", + "JK": "Brighton", + "JL": "Lincoln", + "JM": "Reading", + "JN": "Chelmsford", + "JO": "Oxford", + "JP": "Liverpool", + "JR": "Newcastle-upon-Tyne", + "JS": "Inverness", + "JT": "Bournemouth", + "JU": "Leicester", + "JV": "Lincoln", + "JW": "Birmingham", + "JX": "Huddersfield", + "JY": "Exeter", + "JZ": "County Down", + "K": "Liverpool", + "KA": "Liverpool", + "KB": "Liverpool", + "KC": "Liverpool", + "KD": "Liverpool", + "KE": "Maidstone", + "KF": "Liverpool", + "KG": "Cardiff", + "KH": "Hull", + "KJ": "Bournemouth", + "KK": "Maidstone", + "KL": "Maidstone", + "KM": "Maidstone", + "KN": "Maidstone", + "KO": "Maidstone", + "KP": "Maidstone", + "KR": "Maidstone", + "KS": "Edinburgh", + "KT": "Maidstone", + "KU": "Sheffield", + "KV": "Coventry", + "KW": "Sheffield", + "KX": "Luton", + "KY": "Sheffield", + "KZ": "County Antrim", + "L": "Glamorganshire", + "LA": "London (North-West) (used for London County Council before 1965)", + "LB": "London (North-West) (used for London County Council before 1965)", + "LC": "London (North-West) (used for London County Council before 1965)", + "LD": "London (North-West) (used for London County Council before 1965)", + "LE": "London (North-West) (used for London County Council before 1965)", + "LF": "London (North-West) (used for London County Council before 1965)", + "LG": "Chester", + "LH": "London (North-West) (used for London County Council before 1965)", + "LK": "London (North-West) (used for London County Council before 1965)", + "LL": "London (North-West) (used for London County Council before 1965)", + "LM": "London (North-West) (used for London County Council before 1965)", + "LN": "London (North-West) (used for London County Council before 1965)", + "LO": "London (North-West) (used for London County Council before 1965)", + "LP": "London (North-West) (used for London County Council before 1965)", + "LR": "London (North-West) (used for London County Council before 1965)", + "LS": "Edinburgh", + "LT": "London (North-West) (used for London County Council before 1965)", + "LU": "London (North-West) (used for London County Council before 1965)", + "LV": "Liverpool", + "LW": "London (North-West) (used for London County Council before 1965)", + "LX": "London (North-West) (used for London County Council before 1965)", + "LY": "London (North-West) (used for London County Council before 1965)", + "LZ": "County Armagh", + "M": "Cheshire", + "MA": "Chester", + "MB": "Chester", + "MC": "London (North-East) (used for Middlesex before 1965)", + "MD": "London (North-East) (used for Middlesex before 1965)", + "ME": "London (North-East) (used for Middlesex before 1965)", + "MF": "London (North-East) (used for Middlesex before 1965)", + "MG": "London (North-East) (used for Middlesex before 1965)", + "MH": "London (North-East) (used for Middlesex before 1965)", + "MJ": "Luton", + "MK": "London (North-East) (used for Middlesex before 1965)", + "ML": "London (North-East) (used for Middlesex before 1965)", + "MM": "London (North-East) (used for Middlesex before 1965)", + "MN": "used in the Isle of Man", + "MO": "Reading", + "MP": "London (North-East) (used for Middlesex before 1965)", + "MR": "Swindon", + "MS": "Edinburgh", + "MT": "London (North-East) (used for Middlesex before 1965)", + "MU": "London (North-East) (used for Middlesex before 1965)", + "MV": "London (North-East) (used for Middlesex before 1965)", + "MW": "Swindon", + "MX": "London (North-East) (used for Middlesex before 1965)", + "MY": "London (North-East) (used for Middlesex before 1965)", + "MZ": "Belfast", + "N": "Manchester", + "NA": "Manchester", + "NB": "Manchester", + "NC": "Manchester", + "ND": "Manchester", + "NE": "Manchester", + "NF": "Manchester", + "NG": "Norwich", + "NH": "Northampton", + "NJ": "Brighton", + "NK": "Luton", + "NL": "Newcastle-upon-Tyne", + "NM": "Luton", + "NN": "Nottingham", + "NO": "Chelmsford", + "NP": "Worcester", + "NR": "Leicester", + "NS": "Glasgow", + "NT": "Shrewsbury", + "NU": "Nottingham", + "NV": "Northampton", + "NW": "Leeds", + "NX": "Dudley", + "NY": "Cardiff", + "NZ": "County Londonderry/Derry", + "O": "Birmingham", + "OA": "Birmingham", + "OB": "Birmingham", + "OC": "Birmingham", + "OD": "Exeter", + "OE": "Birmingham", + "OF": "Birmingham", + "OG": "Birmingham", + "OH": "Birmingham", + "OI": "Belfast", + "OJ": "Birmingham", + "OK": "Birmingham", + "OL": "Birmingham", + "OM": "Birmingham", + "ON": "Birmingham", + "OO": "Chelmsford", + "OP": "Birmingham", + "OR": "Portsmouth", + "OS": "Glasgow", + "OT": "Portsmouth", + "OU": "Bristol", + "OV": "Birmingham", + "OW": "Southampton ", + "OX": "Birmingham", + "OY": "London (North-West)", + "OZ": "Belfast", + "P": "Surrey", + "PA": "Guildford", + "PB": "Guildford", + "PC": "Guildford", + "PD": "Guildford", + "PE": "Guildford", + "PF": "Guildford", + "PG": "Guildford", + "PH": "Guildford", + "PJ": "Guildford", + "PK": "Guildford", + "PL": "Guildford", + "PM": "Guildford", + "PN": "Brighton", + "PO": "Portsmouth (GPO formerly used for General Post Office vehicles)", + "PP": "Luton", + "PR": "Bournemouth", + "PS": "Aberdeen", + "PT": "Newcastle-upon-Tyne", + "PU": "Chelmsford", + "PV": "Ipswich", + "PW": "Norwich", + "PX": "Portsmouth", + "PY": "Middlesbrough", + "PZ": "Belfast", + "R": "Derbyshire", + "RA": "Nottingham", + "RB": "Nottingham", + "RC": "Nottingham", + "RD": "Reading", + "RE": "Stoke-on-Trent", + "RF": "Stoke-on-Trent", + "RG": "Newcastle-upon-Tyne", + "RH": "Hull", + "RJ": "Manchester", + "RK": "London (North-West)", + "RL": "Truro", + "RM": "Carlisle", + "RN": "Preston", + "RO": "Luton", + "RP": "Northampton", + "RR": "Nottingham", + "RS": "Aberdeen", + "RT": "Ipswich", + "RU": "Bournemouth", + "RV": "Portsmouth", + "RW": "Coventry", + "RX": "Reading", + "RY": "Leicester", + "RZ": "County Antrim", + "S": "Edinburgh", + "SA": "Aberdeen", + "SB": "Glasgow", + "SC": "Edinburgh", + "SD": "Glasgow", + "SE": "Aberdeen", + "SF": "Edinburgh", + "SG": "Edinburgh", + "SH": "Edinburgh", + "SJ": "Glasgow", + "SK": "Inverness", + "SL": "Dundee", + "SM": "Carlisle", + "SN": "Dundee", + "SO": "Aberdeen", + "SP": "Dundee", + "SR": "Dundee", + "SS": "Aberdeen", + "ST": "Inverness", + "SU": "Glasgow", + "SW": "Carlisle", + "SX": "Edinburgh", + "T": "Devon", + "TA": "Exeter", + "TB": "Liverpool", + "TC": "Bristol", + "TD": "Manchester", + "TE": "Manchester", + "TF": "Reading", + "TG": "Cardiff", + "TH": "Swansea", + "TJ": "Liverpool", + "TK": "Exeter", + "TL": "Lincoln", + "TM": "Luton", + "TN": "Newcastle-upon-Tyne", + "TO": "Nottingham", + "TP": "Portsmouth", + "TR": "Southampton ", + "TS": "Dundee", + "TT": "Exeter", + "TU": "Chester", + "TV": "Nottingham", + "TW": "Chelmsford", + "TX": "Cardiff", + "TY": "Newcastle-upon-Tyne", + "TZ": "Belfast", + "U": "Leeds", + "UA": "Leeds", + "UB": "Leeds", + "UC": "London (Central)", + "UD": "Oxford", + "UE": "Dudley", + "UF": "Brighton", + "UG": "Leeds", + "UH": "Cardiff", + "UI": "County Londonderry/Derry", + "UJ": "Shrewsbury", + "UK": "Birmingham", + "UL": "London (Central)", + "UM": "Leeds", + "UN": "Exeter", + "UO": "Exeter", + "UP": "Newcastle-upon-Tyne", + "UR": "Luton", + "US": "Glasgow", + "UT": "Leicester", + "UU": "London (Central)", + "UV": "London (Central)", + "UW": "London (Central)", + "UX": "Shrewsbury", + "UY": "Worcester", + "UZ": "Belfast", + "V": "Lanarkshire", + "VA": "Peterborough", + "VB": "Maidstone", + "VC": "Coventry", + "VD": "Lanarkshire/Luton", + "VE": "Peterborough", + "VF": "Norwich", + "VG": "Norwich", + "VH": "Huddersfield", + "VJ": "Gloucester", + "VK": "Newcastle-upon-Tyne", + "VL": "Lincoln", + "VM": "Manchester", + "VN": "Middlesbrough", + "VO": "Nottingham", + "VP": "Birmingham", + "VR": "Manchester", + "VS": "Luton", + "VT": "Stoke-on-Trent", + "VU": "Manchester", + "VV": "Northampton", + "VW": "Chelmsford", + "VX": "Chelmsford", + "VY": "Leeds", + "VZ": "County Tyrone", + "W": "Sheffield", + "WA": "Sheffield", + "WB": "Sheffield", + "WC": "Chelmsford", + "WD": "Dudley", + "WE": "Sheffield", + "WF": "Sheffield", + "WG": "Sheffield", + "WH": "Manchester or Bolton", + "WJ": "Sheffield", + "WK": "Coventry", + "WL": "Oxford", + "WM": "Liverpool", + "WN": "Swansea", + "WO": "Cardiff", + "WP": "Worcester", + "WR": "Leeds", + "WS": "Bristol", + "WT": "Leeds", + "WU": "Leeds", + "WV": "Brighton", + "WW": "Leeds", + "WX": "Leeds", + "WY": "Leeds", + "WZ": "Belfast", + "X": "Northumberland", + "XI": "Belfast", + "XZ": "County Armagh", + "Y": "Somerset", + "YA": "Taunton", + "YB": "Taunton", + "YC": "Taunton", + "YD": "Taunton", + "YE": "London (Central)", + "YF": "London (Central)", + "YG": "Leeds", + "YH": "London (Central)", + "YJ": "Brighton", + "YK": "London (Central)", + "YL": "London (Central)", + "YM": "London (Central)", + "YN": "London (Central)", + "YO": "London (Central)", + "YP": "London (Central)", + "YR": "London (Central)", + "YS": "Glasgow", + "YT": "London (Central)", + "YU": "London (Central)", + "YV": "London (Central)", + "YW": "London (Central)", + "YX": "London (Central)", + "YY": "London (Central)", + "YZ": "County Londonderry" + }, + "modern_style": { + "AA": [ + "Anglia", + "Peterborough" + ], + "AB": [ + "Anglia", + "Peterborough" + ], + "AC": [ + "Anglia", + "Peterborough" + ], + "AD": [ + "Anglia", + "Peterborough" + ], + "AE": [ + "Anglia", + "Peterborough" + ], + "AF": [ + "Anglia", + "Peterborough" + ], + "AG": [ + "Anglia", + "Peterborough" + ], + "AH": [ + "Anglia", + "Peterborough" + ], + "AJ": [ + "Anglia", + "Peterborough" + ], + "AK": [ + "Anglia", + "Peterborough" + ], + "AL": [ + "Anglia", + "Peterborough" + ], + "AM": [ + "Anglia", + "Peterborough" + ], + "AN": [ + "Anglia", + "Peterborough" + ], + "AO": [ + "Anglia", + "Norwich" + ], + "AP": [ + "Anglia", + "Norwich" + ], + "AR": [ + "Anglia", + "Norwich" + ], + "AS": [ + "Anglia", + "Norwich" + ], + "AT": [ + "Anglia", + "Norwich" + ], + "AU": [ + "Anglia", + "Norwich" + ], + "AV": [ + "Anglia", + "Ipswich" + ], + "AW": [ + "Anglia", + "Ipswich" + ], + "AX": [ + "Anglia", + "Ipswich" + ], + "AY": [ + "Anglia", + "Ipswich" + ], + "BA": [ + "Birmingham", + "Birmingham" + ], + "BB": [ + "Birmingham", + "Birmingham" + ], + "BC": [ + "Birmingham", + "Birmingham" + ], + "BD": [ + "Birmingham", + "Birmingham" + ], + "BE": [ + "Birmingham", + "Birmingham" + ], + "BF": [ + "Birmingham", + "Birmingham" + ], + "BG": [ + "Birmingham", + "Birmingham" + ], + "BH": [ + "Birmingham", + "Birmingham" + ], + "BJ": [ + "Birmingham", + "Birmingham" + ], + "BK": [ + "Birmingham", + "Birmingham" + ], + "BL": [ + "Birmingham", + "Birmingham" + ], + "BM": [ + "Birmingham", + "Birmingham" + ], + "BN": [ + "Birmingham", + "Birmingham" + ], + "BO": [ + "Birmingham", + "Birmingham" + ], + "BP": [ + "Birmingham", + "Birmingham" + ], + "BR": [ + "Birmingham", + "Birmingham" + ], + "BS": [ + "Birmingham", + "Birmingham" + ], + "BT": [ + "Birmingham", + "Birmingham" + ], + "BU": [ + "Birmingham", + "Birmingham" + ], + "BV": [ + "Birmingham", + "Birmingham" + ], + "BW": [ + "Birmingham", + "Birmingham" + ], + "BX": [ + "Birmingham", + "Birmingham" + ], + "BY": [ + "Birmingham", + "Birmingham" + ], + "CA": [ + "Cymru", + "Cardiff" + ], + "CB": [ + "Cymru", + "Cardiff" + ], + "CC": [ + "Cymru", + "Cardiff" + ], + "CD": [ + "Cymru", + "Cardiff" + ], + "CE": [ + "Cymru", + "Cardiff" + ], + "CF": [ + "Cymru", + "Cardiff" + ], + "CG": [ + "Cymru", + "Cardiff" + ], + "CH": [ + "Cymru", + "Cardiff" + ], + "CJ": [ + "Cymru", + "Cardiff" + ], + "CK": [ + "Cymru", + "Cardiff" + ], + "CL": [ + "Cymru", + "Cardiff" + ], + "CM": [ + "Cymru", + "Cardiff" + ], + "CN": [ + "Cymru", + "Cardiff" + ], + "CO": [ + "Cymru", + "Cardiff" + ], + "CP": [ + "Cymru", + "Swansea" + ], + "CR": [ + "Cymru", + "Swansea" + ], + "CS": [ + "Cymru", + "Swansea" + ], + "CT": [ + "Cymru", + "Swansea" + ], + "CU": [ + "Cymru", + "Swansea" + ], + "CV": [ + "Cymru", + "Swansea" + ], + "CW": [ + "Cymru", + "Bangor" + ], + "CX": [ + "Cymru", + "Bangor" + ], + "CY": [ + "Cymru", + "Bangor" + ], + "DA": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DB": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DC": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DD": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DE": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DF": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DG": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DH": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DJ": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DK": [ + "Deeside to Shrewsbury", + "Chester" + ], + "DL": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DM": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DN": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DO": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DP": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DR": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DS": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DT": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DU": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DV": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DW": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DX": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "DY": [ + "Deeside to Shrewsbury", + "Shrewsbury" + ], + "EA": [ + "Essex", + "Chelmsford" + ], + "EB": [ + "Essex", + "Chelmsford" + ], + "EC": [ + "Essex", + "Chelmsford" + ], + "ED": [ + "Essex", + "Chelmsford" + ], + "EE": [ + "Essex", + "Chelmsford" + ], + "EF": [ + "Essex", + "Chelmsford" + ], + "EG": [ + "Essex", + "Chelmsford" + ], + "EH": [ + "Essex", + "Chelmsford" + ], + "EJ": [ + "Essex", + "Chelmsford" + ], + "EK": [ + "Essex", + "Chelmsford" + ], + "EL": [ + "Essex", + "Chelmsford" + ], + "EM": [ + "Essex", + "Chelmsford" + ], + "EN": [ + "Essex", + "Chelmsford" + ], + "EO": [ + "Essex", + "Chelmsford" + ], + "EP": [ + "Essex", + "Chelmsford" + ], + "ER": [ + "Essex", + "Chelmsford" + ], + "ES": [ + "Essex", + "Chelmsford" + ], + "ET": [ + "Essex", + "Chelmsford" + ], + "EU": [ + "Essex", + "Chelmsford" + ], + "EV": [ + "Essex", + "Chelmsford" + ], + "EW": [ + "Essex", + "Chelmsford" + ], + "EX": [ + "Essex", + "Chelmsford" + ], + "EY": [ + "Essex", + "Chelmsford" + ], + "FA": [ + "Forest and Fens", + "Nottingham" + ], + "FB": [ + "Forest and Fens", + "Nottingham" + ], + "FC": [ + "Forest and Fens", + "Nottingham" + ], + "FD": [ + "Forest and Fens", + "Nottingham" + ], + "FE": [ + "Forest and Fens", + "Nottingham" + ], + "FF": [ + "Forest and Fens", + "Nottingham" + ], + "FG": [ + "Forest and Fens", + "Nottingham" + ], + "FH": [ + "Forest and Fens", + "Nottingham" + ], + "FJ": [ + "Forest and Fens", + "Nottingham" + ], + "FK": [ + "Forest and Fens", + "Nottingham" + ], + "FL": [ + "Forest and Fens", + "Nottingham" + ], + "FM": [ + "Forest and Fens", + "Nottingham" + ], + "FN": [ + "Forest and Fens", + "Nottingham" + ], + "FP": [ + "Forest and Fens", + "Nottingham" + ], + "FR": [ + "Forest and Fens", + "Lincoln" + ], + "FS": [ + "Forest and Fens", + "Lincoln" + ], + "FT": [ + "Forest and Fens", + "Lincoln" + ], + "FV": [ + "Forest and Fens", + "Lincoln" + ], + "FW": [ + "Forest and Fens", + "Lincoln" + ], + "FX": [ + "Forest and Fens", + "Lincoln" + ], + "FY": [ + "Forest and Fens", + "Lincoln" + ], + "GA": [ + "Garden of England", + "Maidstone" + ], + "GB": [ + "Garden of England", + "Maidstone" + ], + "GC": [ + "Garden of England", + "Maidstone" + ], + "GD": [ + "Garden of England", + "Maidstone" + ], + "GE": [ + "Garden of England", + "Maidstone" + ], + "GF": [ + "Garden of England", + "Maidstone" + ], + "GG": [ + "Garden of England", + "Maidstone" + ], + "GH": [ + "Garden of England", + "Maidstone" + ], + "GJ": [ + "Garden of England", + "Maidstone" + ], + "GK": [ + "Garden of England", + "Maidstone" + ], + "GL": [ + "Garden of England", + "Maidstone" + ], + "GM": [ + "Garden of England", + "Maidstone" + ], + "GN": [ + "Garden of England", + "Maidstone" + ], + "GO": [ + "Garden of England", + "Maidstone" + ], + "GP": [ + "Garden of England", + "Brighton" + ], + "GR": [ + "Garden of England", + "Brighton" + ], + "GS": [ + "Garden of England", + "Brighton" + ], + "GT": [ + "Garden of England", + "Brighton" + ], + "GU": [ + "Garden of England", + "Brighton" + ], + "GV": [ + "Garden of England", + "Brighton" + ], + "GX": [ + "Garden of England", + "Brighton" + ], + "GY": [ + "Garden of England", + "Brighton" + ], + "HA": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HB": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HC": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HD": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HE": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HF": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HG": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HH": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HJ": [ + "Hampshire and Dorset", + "Bournemouth" + ], + "HK": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HL": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HM": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HN": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HO": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HP": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HR": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HS": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HT": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HU": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HV": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HX": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HY": [ + "Hampshire and Dorset", + "Portsmouth" + ], + "HW": [ + "Hampshire and Dorset", + "Portsmouth (Used exclusively for the Isle of Wight)" + ], + "KA": [ + "-", + "Luton" + ], + "KB": [ + "-", + "Luton" + ], + "KC": [ + "-", + "Luton" + ], + "KD": [ + "-", + "Luton" + ], + "KE": [ + "-", + "Luton" + ], + "KF": [ + "-", + "Luton" + ], + "KG": [ + "-", + "Luton" + ], + "KH": [ + "-", + "Luton" + ], + "KJ": [ + "-", + "Luton" + ], + "KK": [ + "-", + "Luton" + ], + "KL": [ + "-", + "Luton" + ], + "KM": [ + "-", + "Northampton" + ], + "KN": [ + "-", + "Northampton" + ], + "KO": [ + "-", + "Northampton" + ], + "KP": [ + "-", + "Northampton" + ], + "KR": [ + "-", + "Northampton" + ], + "KS": [ + "-", + "Northampton" + ], + "KT": [ + "-", + "Northampton" + ], + "KU": [ + "-", + "Northampton" + ], + "KV": [ + "-", + "Northampton" + ], + "KW": [ + "-", + "Northampton" + ], + "KX": [ + "-", + "Northampton" + ], + "KY": [ + "-", + "Northampton" + ], + "LA": [ + "London", + "Wimbledon" + ], + "LB": [ + "London", + "Wimbledon" + ], + "LC": [ + "London", + "Wimbledon" + ], + "LD": [ + "London", + "Wimbledon" + ], + "LE": [ + "London", + "Wimbledon" + ], + "LF": [ + "London", + "Wimbledon" + ], + "LG": [ + "London", + "Wimbledon" + ], + "LH": [ + "London", + "Wimbledon" + ], + "LJ": [ + "London", + "Wimbledon" + ], + "LK": [ + "London", + "Stanmore" + ], + "LL": [ + "London", + "Stanmore" + ], + "LM": [ + "London", + "Stanmore" + ], + "LN": [ + "London", + "Stanmore" + ], + "LO": [ + "London", + "Stanmore" + ], + "LP": [ + "London", + "Stanmore" + ], + "LR": [ + "London", + "Stanmore" + ], + "LS": [ + "London", + "Stanmore" + ], + "LT": [ + "London", + "Stanmore" + ], + "LU": [ + "London", + "Sidcup" + ], + "LV": [ + "London", + "Sidcup" + ], + "LW": [ + "London", + "Sidcup" + ], + "LX": [ + "London", + "Sidcup" + ], + "LY": [ + "London", + "Sidcup" + ], + "MA": [ + "Manchester and Merseyside", + "Manchester" + ], + "MB": [ + "Manchester and Merseyside", + "Manchester" + ], + "MC": [ + "Manchester and Merseyside", + "Manchester" + ], + "MD": [ + "Manchester and Merseyside", + "Manchester" + ], + "ME": [ + "Manchester and Merseyside", + "Manchester" + ], + "MF": [ + "Manchester and Merseyside", + "Manchester" + ], + "MG": [ + "Manchester and Merseyside", + "Manchester" + ], + "MH": [ + "Manchester and Merseyside", + "Manchester" + ], + "MJ": [ + "Manchester and Merseyside", + "Manchester" + ], + "MK": [ + "Manchester and Merseyside", + "Manchester" + ], + "ML": [ + "Manchester and Merseyside", + "Manchester" + ], + "MM": [ + "Manchester and Merseyside", + "Manchester" + ], + "MN": [ + "Manchester and Merseyside", + "Manchester" + ], + "MO": [ + "Manchester and Merseyside", + "Manchester" + ], + "MP": [ + "Manchester and Merseyside", + "Manchester" + ], + "MR": [ + "Manchester and Merseyside", + "Manchester" + ], + "MS": [ + "Manchester and Merseyside", + "Manchester" + ], + "MT": [ + "Manchester and Merseyside", + "Manchester" + ], + "MU": [ + "Manchester and Merseyside", + "Manchester" + ], + "MV": [ + "Manchester and Merseyside", + "Manchester" + ], + "MW": [ + "Manchester and Merseyside", + "Manchester" + ], + "MX": [ + "Manchester and Merseyside", + "Manchester" + ], + "MY": [ + "Manchester and Merseyside", + "Manchester" + ], + "NA": [ + "North", + "Newcastle" + ], + "NB": [ + "North", + "Newcastle" + ], + "NC": [ + "North", + "Newcastle" + ], + "ND": [ + "North", + "Newcastle" + ], + "NE": [ + "North", + "Newcastle" + ], + "NF": [ + "North", + "Newcastle" + ], + "NG": [ + "North", + "Newcastle" + ], + "NH": [ + "North", + "Newcastle" + ], + "NJ": [ + "North", + "Newcastle" + ], + "NK": [ + "North", + "Newcastle" + ], + "NL": [ + "North", + "Newcastle" + ], + "NM": [ + "North", + "Newcastle" + ], + "NN": [ + "North", + "Newcastle" + ], + "NO": [ + "North", + "Newcastle" + ], + "NP": [ + "North", + "Stockton" + ], + "NR": [ + "North", + "Stockton" + ], + "NS": [ + "North", + "Stockton" + ], + "NT": [ + "North", + "Stockton" + ], + "NU": [ + "North", + "Stockton" + ], + "NV": [ + "North", + "Stockton" + ], + "NW": [ + "North", + "Stockton" + ], + "NX": [ + "North", + "Stockton" + ], + "NY": [ + "North", + "Stockton" + ], + "OA": [ + "Oxford", + "Oxford" + ], + "OB": [ + "Oxford", + "Oxford" + ], + "OC": [ + "Oxford", + "Oxford" + ], + "OD": [ + "Oxford", + "Oxford" + ], + "OE": [ + "Oxford", + "Oxford" + ], + "OF": [ + "Oxford", + "Oxford" + ], + "OG": [ + "Oxford", + "Oxford" + ], + "OH": [ + "Oxford", + "Oxford" + ], + "OJ": [ + "Oxford", + "Oxford" + ], + "OK": [ + "Oxford", + "Oxford" + ], + "OL": [ + "Oxford", + "Oxford" + ], + "OM": [ + "Oxford", + "Oxford" + ], + "ON": [ + "Oxford", + "Oxford" + ], + "OO": [ + "Oxford", + "Oxford" + ], + "OP": [ + "Oxford", + "Oxford" + ], + "OR": [ + "Oxford", + "Oxford" + ], + "OS": [ + "Oxford", + "Oxford" + ], + "OT": [ + "Oxford", + "Oxford" + ], + "OU": [ + "Oxford", + "Oxford" + ], + "OV": [ + "Oxford", + "Oxford" + ], + "OW": [ + "Oxford", + "Oxford" + ], + "OX": [ + "Oxford", + "Oxford" + ], + "OY": [ + "Oxford", + "Oxford" + ], + "PA": [ + "Preston", + "Preston" + ], + "PB": [ + "Preston", + "Preston" + ], + "PC": [ + "Preston", + "Preston" + ], + "PD": [ + "Preston", + "Preston" + ], + "PE": [ + "Preston", + "Preston" + ], + "PF": [ + "Preston", + "Preston" + ], + "PG": [ + "Preston", + "Preston" + ], + "PH": [ + "Preston", + "Preston" + ], + "PJ": [ + "Preston", + "Preston" + ], + "PK": [ + "Preston", + "Preston" + ], + "PL": [ + "Preston", + "Preston" + ], + "PM": [ + "Preston", + "Preston" + ], + "PN": [ + "Preston", + "Preston" + ], + "PO": [ + "Preston", + "Preston" + ], + "PP": [ + "Preston", + "Preston" + ], + "PR": [ + "Preston", + "Preston" + ], + "PS": [ + "Preston", + "Preston" + ], + "PT": [ + "Preston", + "Preston" + ], + "PU": [ + "Preston", + "Carlisle" + ], + "PV": [ + "Preston", + "Carlisle" + ], + "PW": [ + "Preston", + "Carlisle" + ], + "PX": [ + "Preston", + "Carlisle" + ], + "PY": [ + "Preston", + "Carlisle" + ], + "RA": [ + "Reading", + "Reading" + ], + "RB": [ + "Reading", + "Reading" + ], + "RC": [ + "Reading", + "Reading" + ], + "RD": [ + "Reading", + "Reading" + ], + "RE": [ + "Reading", + "Reading" + ], + "RF": [ + "Reading", + "Reading" + ], + "RG": [ + "Reading", + "Reading" + ], + "RH": [ + "Reading", + "Reading" + ], + "RJ": [ + "Reading", + "Reading" + ], + "RK": [ + "Reading", + "Reading" + ], + "RL": [ + "Reading", + "Reading" + ], + "RM": [ + "Reading", + "Reading" + ], + "RN": [ + "Reading", + "Reading" + ], + "RO": [ + "Reading", + "Reading" + ], + "RP": [ + "Reading", + "Reading" + ], + "RR": [ + "Reading", + "Reading" + ], + "RS": [ + "Reading", + "Reading" + ], + "RT": [ + "Reading", + "Reading" + ], + "RU": [ + "Reading", + "Reading" + ], + "RV": [ + "Reading", + "Reading" + ], + "RW": [ + "Reading", + "Reading" + ], + "RX": [ + "Reading", + "Reading" + ], + "RY": [ + "Reading", + "Reading" + ], + "SA": [ + "Scotland", + "Glasgow" + ], + "SB": [ + "Scotland", + "Glasgow" + ], + "SC": [ + "Scotland", + "Glasgow" + ], + "SD": [ + "Scotland", + "Glasgow" + ], + "SE": [ + "Scotland", + "Glasgow" + ], + "SF": [ + "Scotland", + "Glasgow" + ], + "SG": [ + "Scotland", + "Glasgow" + ], + "SH": [ + "Scotland", + "Glasgow" + ], + "SJ": [ + "Scotland", + "Glasgow" + ], + "SK": [ + "Scotland", + "Edinburgh" + ], + "SL": [ + "Scotland", + "Edinburgh" + ], + "SM": [ + "Scotland", + "Edinburgh" + ], + "SN": [ + "Scotland", + "Edinburgh" + ], + "SO": [ + "Scotland", + "Edinburgh" + ], + "SP": [ + "Scotland", + "Dundee" + ], + "SR": [ + "Scotland", + "Dundee" + ], + "SS": [ + "Scotland", + "Dundee" + ], + "ST": [ + "Scotland", + "Dundee" + ], + "SU": [ + "Scotland", + "Aberdeen" + ], + "SV": [ + "Scotland", + "Aberdeen" + ], + "SW": [ + "Scotland", + "Aberdeen" + ], + "SX": [ + "Scotland", + "Inverness" + ], + "SY": [ + "Scotland", + "Inverness" + ], + "VA": [ + "Severn Valley", + "Worcester" + ], + "VB": [ + "Severn Valley", + "Worcester" + ], + "VC": [ + "Severn Valley", + "Worcester" + ], + "VD": [ + "Severn Valley", + "Worcester" + ], + "VE": [ + "Severn Valley", + "Worcester" + ], + "VF": [ + "Severn Valley", + "Worcester" + ], + "VG": [ + "Severn Valley", + "Worcester" + ], + "VH": [ + "Severn Valley", + "Worcester" + ], + "VJ": [ + "Severn Valley", + "Worcester" + ], + "VK": [ + "Severn Valley", + "Worcester" + ], + "VL": [ + "Severn Valley", + "Worcester" + ], + "VM": [ + "Severn Valley", + "Worcester" + ], + "VN": [ + "Severn Valley", + "Worcester" + ], + "VO": [ + "Severn Valley", + "Worcester" + ], + "VP": [ + "Severn Valley", + "Worcester" + ], + "VR": [ + "Severn Valley", + "Worcester" + ], + "VS": [ + "Severn Valley", + "Worcester" + ], + "VT": [ + "Severn Valley", + "Worcester" + ], + "VU": [ + "Severn Valley", + "Worcester" + ], + "VV": [ + "Severn Valley", + "Worcester" + ], + "VW": [ + "Severn Valley", + "Worcester" + ], + "VX": [ + "Severn Valley", + "Worcester" + ], + "VY": [ + "Severn Valley", + "Worcester" + ], + "WA": [ + "West of England", + "Exeter" + ], + "WB": [ + "West of England", + "Exeter" + ], + "WC": [ + "West of England", + "Exeter" + ], + "WD": [ + "West of England", + "Exeter" + ], + "WE": [ + "West of England", + "Exeter" + ], + "WF": [ + "West of England", + "Exeter" + ], + "WG": [ + "West of England", + "Exeter" + ], + "WH": [ + "West of England", + "Exeter" + ], + "WJ": [ + "West of England", + "Exeter" + ], + "WK": [ + "West of England", + "Truro" + ], + "WL": [ + "West of England", + "Truro" + ], + "WM": [ + "West of England", + "Bristol" + ], + "WN": [ + "West of England", + "Bristol" + ], + "WO": [ + "West of England", + "Bristol" + ], + "WP": [ + "West of England", + "Bristol" + ], + "WR": [ + "West of England", + "Bristol" + ], + "WS": [ + "West of England", + "Bristol" + ], + "WT": [ + "West of England", + "Bristol" + ], + "WU": [ + "West of England", + "Bristol" + ], + "WV": [ + "West of England", + "Bristol" + ], + "WW": [ + "West of England", + "Bristol" + ], + "WX": [ + "West of England", + "Bristol" + ], + "WY": [ + "West of England", + "Bristol" + ], + "YA": [ + "Yorkshire", + "Leeds" + ], + "YB": [ + "Yorkshire", + "Leeds" + ], + "YC": [ + "Yorkshire", + "Leeds" + ], + "YD": [ + "Yorkshire", + "Leeds" + ], + "YE": [ + "Yorkshire", + "Leeds" + ], + "YF": [ + "Yorkshire", + "Leeds" + ], + "YG": [ + "Yorkshire", + "Leeds" + ], + "YH": [ + "Yorkshire", + "Leeds" + ], + "YJ": [ + "Yorkshire", + "Leeds" + ], + "YK": [ + "Yorkshire", + "Leeds" + ], + "YL": [ + "Yorkshire", + "Sheffield" + ], + "YM": [ + "Yorkshire", + "Sheffield" + ], + "YN": [ + "Yorkshire", + "Sheffield" + ], + "YO": [ + "Yorkshire", + "Sheffield" + ], + "YP": [ + "Yorkshire", + "Sheffield" + ], + "YR": [ + "Yorkshire", + "Sheffield" + ], + "YS": [ + "Yorkshire", + "Sheffield" + ], + "YT": [ + "Yorkshire", + "Sheffield" + ], + "YU": [ + "Yorkshire", + "Sheffield" + ], + "YV": [ + "Yorkshire", + "Beverley" + ], + "YW": [ + "Yorkshire", + "Beverley" + ], + "YX": [ + "Yorkshire", + "Beverley" + ], + "YY": [ + "Yorkshire", + "Beverley" + ] + } +} \ No newline at end of file diff --git a/generate_json.py b/generate_json.py new file mode 100644 index 0000000..0c88e1c --- /dev/null +++ b/generate_json.py @@ -0,0 +1,16 @@ +import json +modern_style = [[["AA","AB","AC","AD","AE","AF","AG","AH","AJ","AK","AL","AM","AN"],"Anglia","Peterborough"],[["AO","AP","AR","AS","AT","AU"],"Anglia","Norwich"],[["AV","AW","AX","AY"],"Anglia","Ipswich"],[["BA","BB","BC","BD","BE","BF","BG","BH","BJ","BK","BL","BM","BN","BO","BP","BR","BS","BT","BU","BV","BW","BX","BY"],"Birmingham","Birmingham"],[["CA","CB","CC","CD","CE","CF","CG","CH","CJ","CK","CL","CM","CN","CO"],"Cymru","Cardiff"],[["CP","CR","CS","CT","CU","CV"],"Cymru","Swansea"],[["CW","CX","CY"],"Cymru","Bangor"],[["DA","DB","DC","DD","DE","DF","DG","DH","DJ","DK"],"Deeside to Shrewsbury","Chester"],[["DL","DM","DN","DO","DP","DR","DS","DT","DU","DV","DW","DX","DY"],"Deeside to Shrewsbury","Shrewsbury"],[["EA","EB","EC","ED","EE","EF","EG","EH","EJ","EK","EL","EM","EN","EO","EP","ER","ES","ET","EU","EV","EW","EX","EY"],"Essex","Chelmsford"],[["FA","FB","FC","FD","FE","FF","FG","FH","FJ","FK","FL","FM","FN","FP"],"Forest and Fens","Nottingham"],[["FR","FS","FT","FV","FW","FX","FY"],"Forest and Fens","Lincoln"],[["GA","GB","GC","GD","GE","GF","GG","GH","GJ","GK","GL","GM","GN","GO"],"Garden of England","Maidstone"],[["GP","GR","GS","GT","GU","GV","GX","GY"],"Garden of England","Brighton"],[["HA","HB","HC","HD","HE","HF","HG","HH","HJ"],"Hampshire and Dorset","Bournemouth"],[["HK","HL","HM","HN","HO","HP","HR","HS","HT","HU","HV","HX","HY"],"Hampshire and Dorset","Portsmouth"],[["HW"],"Hampshire and Dorset","Portsmouth (Used exclusively for the Isle of Wight)"],[["KA","KB","KC","KD","KE","KF","KG","KH","KJ","KK","KL"],"-","Luton"],[["KM","KN","KO","KP","KR","KS","KT","KU","KV","KW","KX","KY"],"-","Northampton"],[["LA","LB","LC","LD","LE","LF","LG","LH","LJ"],"London","Wimbledon"],[["LK","LL","LM","LN","LO","LP","LR","LS","LT"],"London","Stanmore"],[["LU","LV","LW","LX","LY"],"London","Sidcup"],[["MA","MB","MC","MD","ME","MF","MG","MH","MJ","MK","ML","MM","MN","MO","MP","MR","MS","MT","MU","MV","MW","MX","MY"],"Manchester and Merseyside","Manchester"],[["NA","NB","NC","ND","NE","NF","NG","NH","NJ","NK","NL","NM","NN","NO"],"North","Newcastle"],[["NP","NR","NS","NT","NU","NV","NW","NX","NY"],"North","Stockton"],[["OA","OB","OC","OD","OE","OF","OG","OH","OJ","OK","OL","OM","ON","OO","OP","OR","OS","OT","OU","OV","OW","OX","OY"],"Oxford","Oxford"],[["PA","PB","PC","PD","PE","PF","PG","PH","PJ","PK","PL","PM","PN","PO","PP","PR","PS","PT"],"Preston","Preston"],[["PU","PV","PW","PX","PY"],"Preston","Carlisle"],[["RA","RB","RC","RD","RE","RF","RG","RH","RJ","RK","RL","RM","RN","RO","RP","RR","RS","RT","RU","RV","RW","RX","RY"],"Reading","Reading"],[["SA","SB","SC","SD","SE","SF","SG","SH","SJ"],"Scotland","Glasgow"],[["SK","SL","SM","SN","SO"],"Scotland","Edinburgh"],[["SP","SR","SS","ST"],"Scotland","Dundee"],[["SU","SV","SW"],"Scotland","Aberdeen"],[["SX","SY"],"Scotland","Inverness"],[["VA","VB","VC","VD","VE","VF","VG","VH","VJ","VK","VL","VM","VN","VO","VP","VR","VS","VT","VU","VV","VW","VX","VY"],"Severn Valley","Worcester"],[["WA","WB","WC","WD","WE","WF","WG","WH","WJ"],"West of England","Exeter"],[["WK","WL"],"West of England","Truro"],[["WM","WN","WO","WP","WR","WS","WT","WU","WV","WW","WX","WY"],"West of England","Bristol"],[["YA","YB","YC","YD","YE","YF","YG","YH","YJ","YK"],"Yorkshire","Leeds"],[["YL","YM","YN","YO","YP","YR","YS","YT","YU"],"Yorkshire","Sheffield"],[["YV","YW","YX","YY"],"Yorkshire","Beverley"]] +legacy_style = {"A": "London","AA": "Bournemouth","AB": "Worcester","AC": "Coventry","AD": "Gloucester","AE": "Bristol","AF": "Truro","AG": "Hull","AH": "Norwich","AJ": "Middlesbrough","AK": "Sheffield","AL": "Nottingham","AM": "Swindon","AN": "Reading","AO": "Carlisle","AP": "Brighton","AR": "Chelmsford","AS": "Inverness","AT": "Hull","AU": "Nottingham","AV": "Peterborough","AW": "Shrewsbury","AX": "Cardiff","AY": "Leicester","AZ": "Belfast","B": "Lancashire","BA": "Manchester","BB": "Newcastle-upon-Tyne","BC": "Leicester","BD": "Northampton","BE": "Lincoln","BF": "Stoke-on-Trent","BG": "Liverpool","BH": "Luton","BJ": "Ipswich","BK": "Portsmouth","BL": "Reading","BM": "Luton","BN": "Manchester or Bolton","BO": "Cardiff","BP": "Portsmouth","BR": "Newcastle-upon-Tyne","BS": "Aberdeen","BT": "Leeds","BU": "Manchester","BV": "Preston","BW": "Oxford","BX": "Haverfordwest","BY": "London (North-West)","BZ": "County Down","C": "West Yorkshire","CA": "Chester","CB": "Manchester","CC": "Bangor","CD": "Brighton","CE": "Peterborough","CF": "Reading","CG": "Bournemouth","CH": "Nottingham","CJ": "Gloucester","CK": "Preston","CL": "Norwich","CM": "Liverpool","CN": "Newcastle-upon-Tyne","CO": "Exeter","CP": "Huddersfield","CR": "Southampton ","CS": "Glasgow","CT": "Lincoln","CU": "Newcastle-upon-Tyne","CV": "Truro","CW": "Preston","CX": "Huddersfield","CY": "Swansea","CZ": "Belfast","D": "Kent","DA": "Birmingham","DB": "Manchester","DC": "Middlesbrough","DD": "Gloucester","DE": "Haverfordwest","DF": "Gloucester","DG": "Gloucester","DH": "Dudley","DJ": "Liverpool","DK": "Rochdale, later Manchester","DL": "Portsmouth","DM": "Chester","DN": "Leeds","DO": "Lincoln","DP": "Reading","DR": "Exeter","DS": "Glasgow","DT": "Sheffield","DU": "Coventry","DV": "Exeter","DW": "Cardiff","DX": "Ipswich","DY": "Brighton","DZ": "County Antrim","E": "Staffordshire","EA": "Dudley","EB": "Peterborough","EC": "Preston","ED": "Liverpool","EE": "Lincoln","EF": "Middlesbrough","EG": "Peterborough","EH": "Stoke-on-Trent","EJ": "Haverfordwest","EK": "Liverpool","EL": "Bournemouth","EM": "Liverpool","EN": "Bury, later Manchester","EO": "Preston","EP": "Swansea","ER": "Peterborough","ES": "Dundee","ET": "Sheffield","EU": "Bristol","EV": "Chelmsford","EW": "Peterborough","EX": "Norwich","EY": "Bangor","EZ": "Belfast","F": "Essex","FA": "Stoke-on-Trent","FB": "Bristol","FC": "Oxford","FD": "Dudley","FE": "Lincoln","FF": "Bangor","FG": "Brighton","FH": "Gloucester","FJ": "Exeter","FK": "Dudley","FL": "Peterborough","FM": "Chester","FN": "Maidstone","FO": "Gloucester","FP": "Leicester","FR": "Preston","FS": "Edinburgh","FT": "Newcastle-upon-Tyne","FU": "Lincoln","FV": "Preston","FW": "Lincoln","FX": "Bournemouth","FY": "Liverpool","FZ": "Belfast","G": "Glasgow","GA": "Glasgow","GB": "Glasgow","GC": "London (South-West)","GD": "Glasgow","GE": "Glasgow","GF": "London (South-West)","GG": "Glasgow","GH": "London (South-West)","GJ": "London (South-West)","GK": "London (South-West)","GL": "Truro","GM": "Reading","GN": "London (South-West)","GO": "London (South-West)","GP": "London (South-West)","GR": "Newcastle-upon-Tyne","GS": "Luton","GT": "London (South-West)","GU": "London (South-East)","GV": "Ipswich","GW": "London (South-East)","GX": "London (South-East)","GY": "London (South-East)","GZ": "Belfast","H": "London","HA": "Dudley","HB": "Cardiff","HC": "Brighton","HD": "Huddersfield","HE": "Sheffield","HF": "Liverpool","HG": "Preston","HH": "Carlisle","HJ": "Chelmsford","HK": "Chelmsford","HL": "Sheffield","HM": "London (Central)","HN": "Middlesbrough","HO": "Bournemouth","HP": "Coventry","HR": "Swindon","HS": "Glasgow","HT": "Bristol","HU": "Bristol","HV": "London (Central)","HW": "Bristol","HX": "London (Central)","HY": "Bristol","J": "Durham","JA": "Manchester","JB": "Reading","JC": "Bangor","JD": "London (Central)","JE": "Peterborough","JF": "Leicester","JG": "Maidstone","JH": "Reading","JJ": "Maidstone","JK": "Brighton","JL": "Lincoln","JM": "Reading","JN": "Chelmsford","JO": "Oxford","JP": "Liverpool","JR": "Newcastle-upon-Tyne","JS": "Inverness","JT": "Bournemouth","JU": "Leicester","JV": "Lincoln","JW": "Birmingham","JX": "Huddersfield","JY": "Exeter","JZ": "County Down","K": "Liverpool","KA": "Liverpool","KB": "Liverpool","KC": "Liverpool","KD": "Liverpool","KE": "Maidstone","KF": "Liverpool","KG": "Cardiff","KH": "Hull","KJ": "Maidstone","KK": "Maidstone","KL": "Maidstone","KM": "Maidstone","KN": "Maidstone","KO": "Maidstone","KP": "Maidstone","KR": "Maidstone","KS": "Edinburgh","KT": "Maidstone","KU": "Sheffield","KV": "Coventry","KW": "Sheffield","KX": "Luton","KY": "Sheffield","KZ": "County Antrim","L": "Glamorganshire","LA": "London (North-West) (used for London County Council before 1965)","LB": "London (North-West) (used for London County Council before 1965)","LC": "London (North-West) (used for London County Council before 1965)","LD": "London (North-West) (used for London County Council before 1965)","LE": "London (North-West) (used for London County Council before 1965)","LF": "London (North-West) (used for London County Council before 1965)","LG": "Chester","LH": "London (North-West) (used for London County Council before 1965)","KJ": "Bournemouth","LK": "London (North-West) (used for London County Council before 1965)","LL": "London (North-West) (used for London County Council before 1965)","LM": "London (North-West) (used for London County Council before 1965)","LN": "London (North-West) (used for London County Council before 1965)","LO": "London (North-West) (used for London County Council before 1965)","LP": "London (North-West) (used for London County Council before 1965)","LR": "London (North-West) (used for London County Council before 1965)","LS": "Edinburgh","LT": "London (North-West) (used for London County Council before 1965)","LU": "London (North-West) (used for London County Council before 1965)","LV": "Liverpool","LW": "London (North-West) (used for London County Council before 1965)","LX": "London (North-West) (used for London County Council before 1965)","LY": "London (North-West) (used for London County Council before 1965)","LZ": "County Armagh","M": "Cheshire","MA": "Chester","MB": "Chester","MC": "London (North-East) (used for Middlesex before 1965)","MD": "London (North-East) (used for Middlesex before 1965)","ME": "London (North-East) (used for Middlesex before 1965)","MF": "London (North-East) (used for Middlesex before 1965)","MG": "London (North-East) (used for Middlesex before 1965)","MH": "London (North-East) (used for Middlesex before 1965)","MJ": "Luton","MK": "London (North-East) (used for Middlesex before 1965)","ML": "London (North-East) (used for Middlesex before 1965)","MM": "London (North-East) (used for Middlesex before 1965)","MN": "used in the Isle of Man","MO": "Reading","MP": "London (North-East) (used for Middlesex before 1965)","MR": "Swindon","MS": "Edinburgh","MT": "London (North-East) (used for Middlesex before 1965)","MU": "London (North-East) (used for Middlesex before 1965)","MV": "London (North-East) (used for Middlesex before 1965)","MW": "Swindon","MX": "London (North-East) (used for Middlesex before 1965)","MY": "London (North-East) (used for Middlesex before 1965)","MZ": "Belfast","N": "Manchester","NA": "Manchester","NB": "Manchester","NC": "Manchester","ND": "Manchester","NE": "Manchester","NF": "Manchester","NG": "Norwich","NH": "Northampton","NJ": "Brighton","NK": "Luton","NL": "Newcastle-upon-Tyne","NM": "Luton","NN": "Nottingham","NO": "Chelmsford","NP": "Worcester","NR": "Leicester","NS": "Glasgow","NT": "Shrewsbury","NU": "Nottingham","NV": "Northampton","NW": "Leeds","NX": "Dudley","NY": "Cardiff","NZ": "County Londonderry/Derry","O": "Birmingham","OA": "Birmingham","OB": "Birmingham","OC": "Birmingham","OD": "Exeter","OE": "Birmingham","OF": "Birmingham","OG": "Birmingham","OH": "Birmingham","OI": "Belfast","OJ": "Birmingham","OK": "Birmingham","OL": "Birmingham","OM": "Birmingham","ON": "Birmingham","OO": "Chelmsford","OP": "Birmingham","OR": "Portsmouth","OS": "Glasgow","OT": "Portsmouth","OU": "Bristol","OV": "Birmingham","OW": "Southampton ","OX": "Birmingham","OY": "London (North-West)","OZ": "Belfast","P": "Surrey","PA": "Guildford","PB": "Guildford","PC": "Guildford","PD": "Guildford","PE": "Guildford","PF": "Guildford","PG": "Guildford","PH": "Guildford","PJ": "Guildford","PK": "Guildford","PL": "Guildford","PM": "Guildford","PN": "Brighton","PO": "Portsmouth (GPO formerly used for General Post Office vehicles)","PP": "Luton","PR": "Bournemouth","PS": "Aberdeen","PT": "Newcastle-upon-Tyne","PU": "Chelmsford","PV": "Ipswich","PW": "Norwich","PX": "Portsmouth","PY": "Middlesbrough","PZ": "Belfast","R": "Derbyshire","RA": "Nottingham","RB": "Nottingham","RC": "Nottingham","RD": "Reading","RE": "Stoke-on-Trent","RF": "Stoke-on-Trent","RG": "Newcastle-upon-Tyne","RH": "Hull","RJ": "Manchester","RK": "London (North-West)","RL": "Truro","RM": "Carlisle","RN": "Preston","RO": "Luton","RP": "Northampton","RR": "Nottingham","RS": "Aberdeen","RT": "Ipswich","RU": "Bournemouth","RV": "Portsmouth","RW": "Coventry","RX": "Reading","RY": "Leicester","RZ": "County Antrim","S": "Edinburgh","SA": "Aberdeen","SB": "Glasgow","SC": "Edinburgh","SD": "Glasgow","SE": "Aberdeen","SF": "Edinburgh","SG": "Edinburgh","SH": "Edinburgh","SJ": "Glasgow","SK": "Inverness","SL": "Dundee","SM": "Carlisle","SN": "Dundee","SO": "Aberdeen","SP": "Dundee","SR": "Dundee","SS": "Aberdeen","ST": "Inverness","SU": "Glasgow","SW": "Carlisle","SX": "Edinburgh","T": "Devon","TA": "Exeter","TB": "Liverpool","TC": "Bristol","TD": "Manchester","TE": "Manchester","TF": "Reading","TG": "Cardiff","TH": "Swansea","TJ": "Liverpool","TK": "Exeter","TL": "Lincoln","TM": "Luton","TN": "Newcastle-upon-Tyne","TO": "Nottingham","TP": "Portsmouth","TR": "Southampton ","TS": "Dundee","TT": "Exeter","TU": "Chester","TV": "Nottingham","TW": "Chelmsford","TX": "Cardiff","TY": "Newcastle-upon-Tyne","TZ": "Belfast","U": "Leeds","UA": "Leeds","UB": "Leeds","UC": "London (Central)","UD": "Oxford","UE": "Dudley","UF": "Brighton","UG": "Leeds","UH": "Cardiff","UI": "County Londonderry/Derry","UJ": "Shrewsbury","UK": "Birmingham","UL": "London (Central)","UM": "Leeds","UN": "Exeter","UO": "Exeter","UP": "Newcastle-upon-Tyne","UR": "Luton","US": "Glasgow","UT": "Leicester","UU": "London (Central)","UV": "London (Central)","UW": "London (Central)","UX": "Shrewsbury","UY": "Worcester","UZ": "Belfast","V": "Lanarkshire","VA": "Peterborough","VB": "Maidstone","VC": "Coventry","VD": "Lanarkshire/Luton","VE": "Peterborough","VF": "Norwich","VG": "Norwich","VH": "Huddersfield","VJ": "Gloucester","VK": "Newcastle-upon-Tyne","VL": "Lincoln","VM": "Manchester","VN": "Middlesbrough","VO": "Nottingham","VP": "Birmingham","VR": "Manchester","VS": "Luton","VT": "Stoke-on-Trent","VU": "Manchester","VV": "Northampton","VW": "Chelmsford","VX": "Chelmsford","VY": "Leeds","VZ": "County Tyrone","W": "Sheffield","WA": "Sheffield","WB": "Sheffield","WC": "Chelmsford","WD": "Dudley","WE": "Sheffield","WF": "Sheffield","WG": "Sheffield","WH": "Manchester or Bolton","WJ": "Sheffield","WK": "Coventry","WL": "Oxford","WM": "Liverpool","WN": "Swansea","WO": "Cardiff","WP": "Worcester","WR": "Leeds","WS": "Bristol","WT": "Leeds","WU": "Leeds","WV": "Brighton","WW": "Leeds","WX": "Leeds","WY": "Leeds","WZ": "Belfast","X": "Northumberland","XI": "Belfast","XZ": "County Armagh","Y": "Somerset","YA": "Taunton","YB": "Taunton","YC": "Taunton","YD": "Taunton","YE": "London (Central)","YF": "London (Central)","YG": "Leeds","YH": "London (Central)","YJ": "Brighton","YK": "London (Central)","YL": "London (Central)","YM": "London (Central)","YN": "London (Central)","YO": "London (Central)","YP": "London (Central)","YR": "London (Central)","YS": "Glasgow","YT": "London (Central)","YU": "London (Central)","YV": "London (Central)","YW": "London (Central)","YX": "London (Central)","YY": "London (Central)","YZ": "County Londonderry",} + + +area_codes = {"legacy_style":{}, "modern_style":{}} +for i in modern_style: + for y in i[0]: + area_codes["modern_style"][y] = [i[1], i[2]] + +for i in legacy_style: + area_codes["legacy_style"][i] = legacy_style[i] + + +with open("2013_area_codes.json", "w") as f: + json.dump(area_codes, f, indent=4) \ No newline at end of file diff --git a/makefile b/makefile new file mode 100644 index 0000000..e595a5a --- /dev/null +++ b/makefile @@ -0,0 +1,60 @@ +SHELL := /bin/bash +MIN_PYTHON_VERSION = 3.11.0 +INSTALLED_PYTHON := $(shell python -V | grep -Po '(?<=Python)(.+)') +MIN_VERSION_MET := $(shell if awk "BEGIN {exit !($(INSTALLED_PYTHON) >= $(MIN_PYTHON_VERSION))}"; then echo true; else echo false; fi) +LOCAL_PYTHON_PATH = .Python/bin/python$(shell echo $(MIN_PYTHON_VERSION)|grep -Po '[0-9]{1,2}.[0-9]{1,2}') +MINIMUM_COVERAGE = 80 +WD = $(shell pwd) + +define venv_run + source .venv/bin/activate && $1 +endef + +all: init standards test + +create-environment: +ifeq ($(MIN_VERSION_MET), true) + python -m venv .venv +else +ifeq (,$(wildcard $(LOCAL_PYTHON_PATH))) + mkdir -p .Python + wget https://www.python.org/ftp/python/$(MIN_PYTHON_VERSION)/Python-$(MIN_PYTHON_VERSION).tgz -O Python-$(MIN_PYTHON_VERSION).tgz + tar -xvzf Python-$(MIN_PYTHON_VERSION).tgz + cd Python-$(MIN_PYTHON_VERSION) && ./configure --prefix $(WD)/.Python && make && make install + rm Python-$(MIN_PYTHON_VERSION).tgz + rm -R Python-$(MIN_PYTHON_VERSION) +endif + $(LOCAL_PYTHON_PATH) -m venv .venv +endif + +install-dev: + $(call venv_run, pip install --upgrade pip) + $(call venv_run, pip install .[dev]) + $(call venv_run, pip install -e .) +install: + $(call venv_run, pip install --upgrade pip) + $(call venv_run, pip install .) + +dev-init: create-environment install-dev +init: create-environment install + +# testing / standards +pytest: + $(call venv_run, pytest -v) +safety: + $(call venv_run, safety check) +bandit: + $(call venv_run, bandit -r src/) +flake: + $(call venv_run, flake8 src/) +coverage: + $(call venv_run, coverage run --omit .venv -m pytest && coverage report -m --fail-under=$(MINIMUM_COVERAGE)) +autopep8: + $(call venv_run, autopep8 --in-place --recursive src/*) +pkg_size: + test/package_size.sh +test: pytest coverage pkg_size +standards: autopep8 bandit flake safety + +clean: + rm -Rf build dist .pytest_cache .coverage src/droppii/__pycache__ test/__pycache__ \ No newline at end of file diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..34bd5d0 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,19 @@ +[project] +name = "uk_plate_reader" +version = "0.0.0" +description = "" +readme = "" +requires-python = ">=3.11" +dependencies = [] +classifiers = [ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: Apache Software License", + "Operating System :: Unix", +] + +[project.optional-dependencies] +dev = ["pytest"] + +[build-system] +requires = ["setuptools>=65.0"] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/src/uk_plate_reader.py b/src/uk_plate_reader.py new file mode 100644 index 0000000..4bac766 --- /dev/null +++ b/src/uk_plate_reader.py @@ -0,0 +1,56 @@ +import json +import sys + +with open("./data/area_codes.json", "r") as f: + areas = json.load(f) + +def get_legacy_year(plate:str): + base_year = 1983 + try: + year_indicator = plate[0] + except IndexError: + return False + year_offset = ord(year_indicator.upper()) - ord("A") + year = base_year + year_offset + if year < 1983 or year >= 2001: + year = False + return year + +def get_year(plate:str)->int: + year_indicator = int(plate[2:4]) + if year_indicator >= 50: + year_indicator = year_indicator - 50 + return year_indicator + 2000 + +def get_legacy_area(plate:str): + if len(plate.replace(" ","")) == 5: + area_code = plate[-1] + elif len(plate.replace(" ", "")) == 6: + area_code = plate[-2:] + return areas.get("legacy_style").get(area_code) + +def get_area(plate:str): + area_code = plate[0:2] + area, _ = areas.get("modern_style").get(area_code) + return area + +def is_legacy(plate): + try: + return int(plate[1]) + except ValueError: + return False + +def read_licence_plate(plate:str): + if is_legacy(plate): + area = get_legacy_area(plate) + year = get_legacy_year(plate) + else: + area = get_area(plate) + year = get_year(plate) + if not area or not year: + raise Exception("Not a valid licence plate") + return [area, year] + +if __name__ == "__main__": + if len(sys.argv) > 1: + print(read_licence_plate(sys.argv[1])) \ No newline at end of file diff --git a/test/test_main.py b/test/test_main.py new file mode 100644 index 0000000..96b992e --- /dev/null +++ b/test/test_main.py @@ -0,0 +1,33 @@ +from uk_plate_reader import read_licence_plate +import pytest # type: ignore + +def test_old_plate_returns_correct_area(): + assert read_licence_plate("N12 ANA")[0] == "Manchester" + assert read_licence_plate("L12 AOE")[0] == "Birmingham" + assert read_licence_plate("L12 AP")[0] == "Surrey" + +def test_new_plate_returns_correct_area(): + assert read_licence_plate("LL07 XYZ")[0] == "London" + assert read_licence_plate("OJ57 XYZ")[0] == "Oxford" + assert read_licence_plate("BB62 XYZ")[0] == "Birmingham" + +def test_old_plate_returns_correct_year(): + assert read_licence_plate("N12 AOE")[1] in [1995, 1996] + assert read_licence_plate("L12 AOE")[1] in [1993, 1994] + +def test_new_plate_returns_correct_year(): + assert read_licence_plate("AB07 XYZ")[1] == 2007 + assert read_licence_plate("AB57 XYZ")[1] in [2007, 2008] + assert read_licence_plate("AB62 XYZ")[1] in [2012, 2013] + +def test_invalid_plate_returns_error(): + for plate in ["A", "ZZ07 LMA", "Z12 ANA", "Y12 ZZZ"]: + with pytest.raises(Exception): + read_licence_plate(plate) + +def test_empty_input_returns_error(): + with pytest.raises(IndexError): + read_licence_plate("") + +def test_legacy_single_char_area(): + assert read_licence_plate("N12 AM")[0] == "Cheshire" \ No newline at end of file