-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
98 lines (81 loc) · 2.79 KB
/
index.ts
File metadata and controls
98 lines (81 loc) · 2.79 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
86
87
88
89
90
91
92
93
94
95
96
97
98
import fs from 'node:fs';
import process from 'node:process';
import * as dotenv from 'dotenv'
dotenv.config();
const schedUrl = process.env.SCHED_URL;
const schedKey = process.env.SCHED_KEY_RO;
const exportFile = 'openfeedback.json';
const schedFile = 'sched.json';
const timeZone = '+02:00';
async function getSessions(raw: boolean = false) {
const response = await fetch(`${schedUrl}/api/session/export?api_key=${schedKey}&format=json&strip_html=Y`);
const sessions = await response.json() as SCSession[];
return raw ? sessions : sessions
.filter(s => s.active && (
s.event_subtype === 'Talk' ||
s.event_subtype === 'Schuss' ||
s.event_subtype === 'Workshop' ||
s.event_subtype === 'Keynote'
));
}
async function getAvatars() {
const response = await fetch(`${schedUrl}/api/user/list?api_key=${schedKey}&format=json&fields=username,avatar`);
return await response.json() as SCAvatar[];
}
function convertSCTimeToOFTime(time: string) {
return time.replace(' ', 'T') + timeZone;
}
function exportOFData(sessions: SCSession[], avatars: SCAvatar[]) {
const avatarByUsername: Record<string, string> = {};
const data: OFData = {
sessions: {},
speakers: {}
};
for (const avatar of avatars) {
avatarByUsername[avatar.username] = avatar.avatar;
}
for (const session of sessions) {
if (!session.speakers?.length) {
console.error(`Session "${session.name}" has no speakers. Skipping...`);
continue;
}
const speakers = session.speakers.map(speaker => {
data.speakers[speaker.id] = {
id: speaker.id,
name: speaker.name,
photoUrl: avatarByUsername[speaker.username] ?? ""
// ...(avatarByUsername[speaker.username] ? { photoUrl: avatarByUsername[speaker.username] } : {})
}
return speaker.id;
});
data.sessions[session.id] = {
id: session.id,
tags: [session.event_type, session.event_subtype],
title: session.name,
startTime: convertSCTimeToOFTime(session.event_start),
endTime: convertSCTimeToOFTime(session.event_end),
trackTitle: session.venue,
speakers
};
}
return data;
}
async function main() {
console.log('Retrieving sessions from sched...');
const sessions = await getSessions();
const avatars = await getAvatars();
const data = exportOFData(sessions, avatars);
fs.writeFileSync(exportFile, JSON.stringify(data, null, 2))
console.log(`Exported data to "${exportFile}" successfully.`);
}
async function debugSched() {
console.log('Retrieving sessions from sched...');
const sessions = await getSessions(true);
fs.writeFileSync(schedFile, JSON.stringify(sessions, null, 2))
console.log(`Exported raw sessions to "${schedFile}" successfully.`);
}
if (process.argv[2] === '--sched') {
debugSched();
} else {
main();
}