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 4c47486
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Each "scraper" is represented within the `scrapers/` directory as a single file.
url: 'Any sort of URL for the meeting goes here',
uid: 'Use any sort of internal identifier that the source uses',
start: [YYYY, MM, DD, H, M],
duration: { minutes: 90 },
duration: { hours: 2, minutes: 0 },
}
```
Please make sure to adjust the `duration.minutes` value if applicable to the meeting.
Please make sure to adjust the `duration.hours` and `duration.minutes` values if applicable to the meeting.
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
51 changes: 51 additions & 0 deletions scrapers/egusd-board.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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 = {
hours: isWorkshop ? 6 : 4,
minutes: isWorkshop ? 30 : 0
}

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

return meetings
}

module.exports = scrapeEGUSDBoard
4 changes: 2 additions & 2 deletions scrapers/sac-board-of-supervisors.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ async function scrapeSacBoardOfSupervisors() {
]

data.push({
title,
title: 'Sac County Board of Supervisors Meeting',
description,
url: link,
uid: guid,
start,
duration: { minutes: 90 },
duration: { hours: 2 },
})
})

Expand Down
2 changes: 1 addition & 1 deletion scrapers/sac-city-council.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ async function scrapeSacCityCouncil() {
url: link,
uid: guid,
start,
duration: { minutes: 90 },
duration: { hours: 2 },
})
})

Expand Down
5 changes: 2 additions & 3 deletions scrapers/scusd-board.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ async function scrapeSCUSDBoard() {
parsedDate.getMinutes(),
]

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

Expand Down

0 comments on commit 4c47486

Please sign in to comment.