Skip to content

Commit

Permalink
Improve get_chamber_name logic
Browse files Browse the repository at this point in the history
  • Loading branch information
alexobaseki committed Sep 4, 2024
1 parent 0ed7718 commit 448f5c2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions openstates/importers/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,16 +78,18 @@ def get_chamber_name_from_event_name(
self, name: typing.Union[str, tuple]
) -> typing.Union[str, None]:
if isinstance(name, tuple):
possible_chamber_name = name[0].split()[0].lower()
event_name = name[0].lower()
else:
possible_chamber_name = name.split()[0].lower()
event_name = name.lower()

state = lookup(jurisdiction_id=self.jurisdiction_id)

if state.lower and state.lower.name.lower() == possible_chamber_name:
return state.lower.chamber_type
elif state.upper and state.upper.name.lower() == possible_chamber_name:
return state.upper.chamber_type
chamber_types = []
if state.lower and state.lower.name.lower() in event_name:
chamber_types.append(state.lower.chamber_type)
if state.upper and state.upper.name.lower() in event_name:
chamber_types.append(state.upper.chamber_type)
if len(chamber_types) == 1:
return chamber_types[0]
return None

def prepare_for_db(self, data: _JsonDict) -> _JsonDict:
Expand Down

0 comments on commit 448f5c2

Please sign in to comment.