Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🏗 Build Spider: Los Angeles Board of Supervisors #9

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
71 changes: 71 additions & 0 deletions city_scrapers/spiders/losca_Board_of_Supervisors.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from city_scrapers_core.constants import BOARD
from city_scrapers_core.items import Meeting
from city_scrapers_core.spiders import CityScrapersSpider
from dateutil.parser import parse


class LoscaBoardOfSupervisorsSpider(CityScrapersSpider):
name = "losca_Board_of_Supervisors"
agency = "Los Angeles County Board of Supervisors"
timezone = "America/Los_Angeles"
start_urls = ["https://bos.lacounty.gov/board-meeting-agendas/"]

def parse(self, response):
"""Parse meeting items from agency website."""
location = {
"name": "Kenneth Hahn Hall of Administration",
"address": "500 West Temple Street, Room 381B, Los Angeles",
}
# ".card" returns duplicates bc page has ".card"s inside .card elements
# ".upcoming-meeting" returns the correct number of meetings even though
# some of the meetings already happened and are not "upcoming"
for item in response.css(".upcoming-meeting"):
title = item.css(".card-title::text").get()
meeting = Meeting(
title=title,
description="",
classification=BOARD,
start=self._parse_start(item),
end=None,
all_day=False,
time_notes="",
location=location,
links=self._parse_links(item),
source=response.url,
)

meeting["status"] = self._get_status(meeting)
meeting["id"] = self._get_id(meeting)

yield meeting

def _parse_start(self, item):
"""
Parse start datetime as a native datetime object.
Combine the date with the time found in a time.
Page says meetings start at 9:30 but one of them actually started at 11.
Do not hardcode time when parsing.
"""
# => 'Tuesday, September 17, 2024'
date = item.css(".calendar-date time::text").get()

# => '09:30 AM\n PST'
time = item.css(".clock-time time::text").get().split("\n")[0]

datetime = parse(f"{date} {time}")
return datetime

def _parse_links(self, item):
"""
Parse links.
Agenda and PDF version are usually present.
Supplemental and PDF version are sometimes present.
Add all if found.
"""
out = []
links = item.css("a")
for link in links:
title = link.css("span::text").get()
href = link.css("::attr(href)").get()
out.append({"title": title, "href": href})
return out
Loading
Loading