Skip to content

Commit aad684e

Browse files
committed
Debug event scraper.
1 parent 06310bc commit aad684e

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

functions/src/events/scrapeEvents.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,15 +147,23 @@ class HearingScraper extends EventScraper<HearingListItem, Hearing> {
147147
return events.filter(HearingListItem.guard)
148148
}
149149

150-
async getEvent({ EventId }: HearingListItem /* e.g. 4962 */) {
150+
async getEvent() {
151+
const EventId = 5091
151152
const data = await api.getHearing(EventId)
152153
const content = HearingContent.check(data)
153154
const eventInDb = await db
154155
.collection("events")
155156
.doc(`hearing-${String(EventId)}`)
156157
.get()
158+
157159
const eventData = eventInDb.data()
160+
try {
161+
Hearing.check(eventData)
162+
} catch (e) {
163+
console.log(e)
164+
}
158165
const hearing = Hearing.check(eventData)
166+
159167
const shouldScrape = withinCutoff(hearing.startsAt.toDate())
160168

161169
let maybeVideoURL = null
@@ -207,13 +215,26 @@ class HearingScraper extends EventScraper<HearingListItem, Hearing> {
207215
}
208216
}
209217
}
218+
210219
const event: Hearing = {
211220
id: `hearing-${EventId}`,
212221
type: "hearing",
213222
content,
214-
videoURL: maybeVideoURL ? maybeVideoURL : undefined,
215-
videoFetchedAt: maybeVideoURL ? Timestamp.now() : undefined,
216-
videoAssemblyId: transcript ? transcript.id : undefined,
223+
videoURL: hearing.videoURL
224+
? hearing.videoURL
225+
: maybeVideoURL
226+
? maybeVideoURL
227+
: null,
228+
videoFetchedAt: hearing.videoFetchedAt
229+
? hearing.videoFetchedAt
230+
: maybeVideoURL
231+
? Timestamp.now()
232+
: null,
233+
videoAssemblyId: hearing.videoAssemblyId
234+
? hearing.videoAssemblyId
235+
: transcript
236+
? transcript.id
237+
: null,
217238
...this.timestamps(content)
218239
}
219240
return event

functions/src/events/types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ export type Hearing = Static<typeof Hearing>
7878
export const Hearing = BaseEvent.extend({
7979
type: L("hearing"),
8080
content: HearingContent,
81-
videoURL: Optional(String),
82-
videoAssemblyId: Optional(String),
83-
videoFetchedAt: Optional(InstanceOf(Timestamp))
81+
videoURL: Nullable(String),
82+
videoAssemblyId: Nullable(String),
83+
videoFetchedAt: Nullable(InstanceOf(Timestamp))
8484
})
8585

8686
export type Event = Static<typeof Event>

0 commit comments

Comments
 (0)