Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions scrapers/va/csv_bills.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,40 @@ def remove_html_tags(self, text):
clean = re.compile("<.*?>")
return re.sub(clean, "", text)

def chamber_for_action(self, action, chamber_types):
"""Resolve the chamber for a history action and strip its prefix.

Actions are normally prefixed with a chamber code followed by a space,
e.g. "H Prefiled and ordered printed" or
"S Constitutional reading dispensed".

Some actions have no chamber letter and instead begin with a leading
space. Previously the scraper assumed every action started with a valid
chamber letter and did chamber_types[action[0]], which raised a KeyError
on these and halted the scrape -- dropping all signed/vetoed actions.

These prefix-less actions fall into two groups:
* Governor (executive) actions, e.g. "Approved by Governor" or
"Vetoed by Governor".
* Non-governor records such as "Acts of Assembly Chapter text
(CHAP...)" or "Conference Report released", which are legislative in
nature.

Only actions mentioning the Governor are treated as executive; everything
else falls back to "legislature" so we don't mislabel these records as
executive actions.

Returns a (chamber, cleaned_action) tuple.
"""
chamber_code = action[0]
if chamber_code in chamber_types:
return chamber_types[chamber_code], action[2:]

cleaned_action = action.strip()
if "governor" in cleaned_action.lower():
return "executive", cleaned_action
return "legislature", cleaned_action

def load_summaries(self):
resp = self.get_file("Summaries.csv")
reader = csv.reader(resp.splitlines(), delimiter=",")
Expand Down Expand Up @@ -311,9 +345,9 @@ def scrape(self, session=None):
action = hist["history_description"]
action_date = hist["history_date"]
date = dateutil.parser.parse(action_date).date()
chamber = chamber_types[action[0]]
vote_id = hist["history_refid"]
cleaned_action = action[2:]

chamber, cleaned_action = self.chamber_for_action(action, chamber_types)

if re.findall(r"\d{8}D", cleaned_action):
doc_actions[action_date].append(cleaned_action)
Expand Down
Loading