Skip to content

Commit

Permalink
standardise party names on MP import
Browse files Browse the repository at this point in the history
TWFY has different names from previous sources so do some standardising.
Also add Reclaim to shader options
  • Loading branch information
struan committed Feb 28, 2024
1 parent 006f712 commit fa8438b
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion hub/management/commands/import_mps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,25 @@
"Sinn Féin": "#326760",
"Social Democratic and Labour Party": "#2AA82C",
"Speaker of the House of Commons": "#DCDCDC",
"Reclaim": "#101122",
"independent politician": "#DCDCDC",
}

party_map = {
"Conservative": "Conservative Party",
"Conservative and Unionist Party": "Conservative Party",
"Green": "Green Party",
"Green Party (England & Wales)": "Green Party",
"SDLP (Social Democratic & Labour Party)": "Social Democratic and Labour Party",
"DUP": "Democratic Unionist Party",
"Labour": "Labour Party",
"Labour/Co-operative": "Labour Co-operative",
"Speaker": "Speaker of the House of Commons",
"Liberal Democrat": "Liberal Democrats",
"Alba": "Alba Party",
"Independent": "independent politician",
}

MP_IMPORT_COMMANDS = [
"import_mps_relevant_votes",
"import_mps_select_committee_membership",
Expand All @@ -58,6 +74,16 @@ def handle(self, quiet: bool = False, *args, **options):
self.check_for_duplicate_mps()
self.import_mp_images()

def standardise_party(self, party):
orig_party = party
if party_shades.get(party, None) is not None:
return party

if party_map.get(party, None) is not None:
return party_map[party]

return orig_party

# these are separate functions so we can mock them in tests
def get_twfy_df(self):
df = pd.read_csv("https://www.theyworkforyou.com/mps/?f=csv").rename(
Expand Down Expand Up @@ -253,10 +279,11 @@ def import_mps(self):
)
if "Party" in mp:
try:
party = self.standardise_party(mp["Party"])
PersonData.objects.update_or_create(
person=person,
data_type=data_types["party"],
defaults={"data": mp["Party"]},
defaults={"data": party},
)
except PersonData.MultipleObjectsReturned: # pragma: no cover
PersonData.objects.filter(
Expand Down

0 comments on commit fa8438b

Please sign in to comment.