Skip to content

Commit

Permalink
Type checking on events utils, and MD events lat/lon matches. (#5273)
Browse files Browse the repository at this point in the history
* Events: Better type checking for util functions
* MD: Events: match lat/lon
  • Loading branch information
showerst authored Feb 4, 2025
1 parent 32c3d3d commit 8a71e54
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 9 additions & 0 deletions scrapers/md/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re

from utils import LXMLMixin
from utils.events import match_coordinates
from openstates.scrape import Scraper, Event
from openstates.exceptions import EmptyScrape

Expand Down Expand Up @@ -118,6 +119,14 @@ def scrape(self, session=None, start=None, end=None):
classification="committee-meeting",
)

match_coordinates(
event,
{
"house office building": ("38.98021", "-76.49229"),
"miller senate": ("38.97975", "-76.49325"),
},
)

com_name = re.sub(r"[\s\-]*Work Session", "", com_row)
if com_name:
event.add_participant(name=com_name, type="committee", note="host")
Expand Down
8 changes: 5 additions & 3 deletions scrapers/utils/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import operator

from dateutil.relativedelta import relativedelta
from openstates.scrape import Event
from typing import Dict


# the current function to set coordinates requires a
# valid URL and Note, which we often don't have.
# so this will add just coordinates
def set_coordinates(event, lat, lon):
def set_coordinates(event: Event, lat, lon):
# the schema requires strings for these
coords = {
"latitude": str(lat),
Expand All @@ -19,7 +21,7 @@ def set_coordinates(event, lat, lon):
event.__setattr__("location", loc_dict)


def set_location_url(event, url: str):
def set_location_url(event: Event, url: str):
loc_dict = event.location
loc_dict["url"] = url
event.__setattr__("location", loc_dict)
Expand All @@ -28,7 +30,7 @@ def set_location_url(event, url: str):
# loop through a dict of
# {"location string", (lat, lon)} entries
# and update the location lat/lon if any matches are found
def match_coordinates(event, locations):
def match_coordinates(event: Event, locations: Dict[str, tuple]):
for location, coords in locations.items():
if location.lower() in event.location.get("name").lower():
set_coordinates(event, coords[0], coords[1])
Expand Down

0 comments on commit 8a71e54

Please sign in to comment.