forked from graphql/graphql.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_data.ts
More file actions
85 lines (70 loc) · 2.33 KB
/
Copy path_data.ts
File metadata and controls
85 lines (70 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import "server-only"
import { stripHtml } from "string-strip-html"
import { SchedSpeaker, ScheduleSession } from "@/app/conf/2023/types"
import pLimit from "p-limit"
async function fetchData<T>(url: string): Promise<T> {
try {
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
"User-Agent": "GraphQL Conf / GraphQL Foundation",
},
})
const data = await response.json()
return data
} catch (error) {
throw new Error(
`Error fetching data from ${url}: ${(error as Error).message || (error as Error).toString()}`,
)
}
}
const token = process.env.SCHED_ACCESS_TOKEN_2024
async function getUsernames(): Promise<string[]> {
const response = await fetchData<{ username: string }[]>(
`https://graphqlconf2024.sched.com/api/user/list?api_key=${token}&format=json&fields=username`,
)
return response.map(user => user.username)
}
const limit = pLimit(40) // rate limit is 30req/min
async function getSpeakers(): Promise<SchedSpeaker[]> {
const usernames = await getUsernames()
const users = await Promise.all(
usernames.map(username =>
limit(() => {
return fetchData<SchedSpeaker>(
`https://graphqlconf2024.sched.com/api/user/get?api_key=${token}&by=username&term=${username}&format=json&fields=username,company,position,name,about,location,url,avatar,role,socialurls`,
)
}),
),
)
const result = users
.filter(speaker => speaker.role.includes("speaker"))
.map(user => {
return {
...user,
about: stripHtml(user.about).result,
}
})
return result
}
async function getSchedule(): Promise<ScheduleSession[]> {
const sessions = await fetchData<ScheduleSession[]>(
`https://graphqlconf2024.sched.com/api/session/export?api_key=${token}&format=json`,
)
const result = sessions.map(session => {
const { description } = session
if (description?.includes("<")) {
// console.log(`Found HTML element in about field for session "${session.name}"`)
}
// TODO: Preserve formatting??
return {
...session,
description: description && stripHtml(description).result,
}
})
return result
}
export const speakers = await getSpeakers()
// TODO: Collect tags from schedule for speakers.
export const schedule = await getSchedule()