Skip to content

Commit 9303170

Browse files
committed
Improve video scrape start logic.
1 parent 0306548 commit 9303170

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

functions/src/events/scrapeEvents.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,23 @@ class HearingScraper extends EventScraper<HearingListItem, Hearing> {
158158
const hearing = Hearing.check(eventData)
159159
const shouldScrape = withinCutoff(hearing.startsAt.toDate())
160160

161+
let payload: Hearing = {
162+
id: `hearing-${EventId}`,
163+
type: "hearing",
164+
content,
165+
...this.timestamps(content)
166+
}
167+
if (hearing) {
168+
payload = {
169+
...payload,
170+
videoURL: hearing.videoURL,
171+
videoFetchedAt: hearing.videoFetchedAt,
172+
videoAssemblyId: hearing.videoAssemblyId
173+
}
174+
}
161175
let maybeVideoURL = null
162176
let transcript = null
177+
163178
if (!hearing.videoFetchedAt && shouldScrape) {
164179
const req = await fetch(
165180
`https://malegislature.gov/Events/Hearings/Detail/${EventId}`
@@ -203,34 +218,17 @@ class HearingScraper extends EventScraper<HearingListItem, Hearing> {
203218
.set({
204219
videoAssemblyWebhookToken: sha256(newToken)
205220
})
221+
222+
payload = {
223+
...payload,
224+
videoURL: maybeVideoURL,
225+
videoFetchedAt: Timestamp.now(),
226+
videoAssemblyId: transcript.id
227+
}
206228
}
207229
}
208230
}
209231
}
210-
let payload: Hearing = {
211-
id: `hearing-${EventId}`,
212-
type: "hearing",
213-
content,
214-
...this.timestamps(content)
215-
}
216-
if (hearing.videoURL) {
217-
payload = { ...payload, videoURL: hearing.videoURL }
218-
}
219-
if (maybeVideoURL) {
220-
payload = { ...payload, videoURL: maybeVideoURL }
221-
}
222-
if (hearing.videoFetchedAt) {
223-
payload = { ...payload, videoFetchedAt: hearing.videoFetchedAt }
224-
}
225-
if (maybeVideoURL) {
226-
payload = { ...payload, videoFetchedAt: Timestamp.now() }
227-
}
228-
if (hearing.videoAssemblyId) {
229-
payload = { ...payload, videoAssemblyId: hearing.videoAssemblyId }
230-
}
231-
if (transcript) {
232-
payload = { ...payload, videoAssemblyId: transcript.id }
233-
}
234232

235233
const event: Hearing = payload
236234
return event

0 commit comments

Comments
 (0)