Skip to content

Commit

Permalink
Add EGUSD board meeting scraper
Browse files Browse the repository at this point in the history
Refs #1
  • Loading branch information
Jeremia authored and Jeremia committed Jan 7, 2021
1 parent 2124358 commit 215910a
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 9 deletions.
26 changes: 19 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const express = require("express")
const ics = require("ics")

const scrapeEGUSD = require("./scrapers/egusd-board.js")
const scrapeSacBoardOfSupervisors = require("./scrapers/sac-board-of-supervisors.js")
const scrapeSacCityCouncil = require("./scrapers/sac-city-council.js")
const scrapeSCUSD = require("./scrapers/scusd-board.js")
Expand All @@ -12,27 +13,38 @@ app.get("/", (req, res) => {
res.send("OK")
})

app.get("/calendar.ics", (req, res) => {
app.get("/calendar.:format", (req, res) => {
const { format } = req.params
Promise.all([
scrapeSacBoardOfSupervisors(),
scrapeSacCityCouncil(),
scrapeSCUSD(),
scrapeSacBoardOfSupervisors(),
scrapeEGUSD(),
]).then((data) => {
const [cityCouncilMeetings, scusdMeetings, supervisorMeetings] = data
const [supervisorMeetings, cityCouncilMeetings, scusdMeetings, egusdMeetings] = data
// const [egusdMeetings] = data
const meetings = [].concat(
supervisorMeetings,
cityCouncilMeetings,
scusdMeetings,
supervisorMeetings
egusdMeetings,
)
const { error, value } = ics.createEvents(meetings)

if (error) {
res.json({ error })
return
}
res.json(meetings)
return
res.send(value)

if (format === 'json') {
return res.json(meetings)
}

if (format === 'ics') {
return res.send(value)
}

return res.status(404)
})
})

Expand Down
50 changes: 50 additions & 0 deletions scrapers/egusd-board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const cheerio = require("cheerio")
const { timeParse } = require("d3-time-format")
const fetch = require("isomorphic-fetch")

const url = 'http://www.egusd.net/about/leadership/board-of-education/board-meeting-schedule/'
const parseDate = timeParse('%B %e, %Y')

async function scrapeEGUSDBoard() {
const req = await fetch(url)
const text = await req.text()
const $ = cheerio.load(text)
const calendarIcon = $('.wp-svg-calendar.calendar')
const h3 = calendarIcon.closest('h3')
const ul = h3.next('ul')
const lis = ul.find('li')
const meetings = []

lis.each(function(i, li) {
const text = $(li).text()
const [date, ...match] = text.match(/^(\w+\s\d+,\s\d{4})/)
const isRescheduled = text.includes('Rescheduled')
const isWorkshop = text.includes('Board Workshop')

if (isRescheduled) return

const parsedDate = parseDate(date)
const title = isWorkshop ? 'EGUSD Board Workshop' : 'EGUSD Board Meeting'
const start = [
parsedDate.getFullYear(),
parsedDate.getMonth() + 1,
parsedDate.getDate(),
isWorkshop ? 8 : 18,
isWorkshop ? 30 : 0,
]
const duration = {
minutes: isWorkshop ? 390 : 240
}

meetings.push({
title,
description: '',
start,
duration,
})
})

return meetings
}

module.exports = scrapeEGUSDBoard
3 changes: 1 addition & 2 deletions scrapers/scusd-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ async function scrapeSCUSDBoard() {
parsedDate.getMinutes(),
]

// debugger
data.push({
title,
title: 'SCUSD Board Meeting',
start,
description: "",
duration: { minutes: 90 },
Expand Down

0 comments on commit 215910a

Please sign in to comment.