Skip to content

Commit 9650d1b

Browse files
committed
Add support for pulling in penta format schemas into the pretalx backend.
1 parent a22aba4 commit 9650d1b

File tree

4 files changed

+58
-11
lines changed

4 files changed

+58
-11
lines changed

config/default.yaml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ conference:
122122
name: "FOSDEM 2021"
123123

124124

125+
# Schema may either be "json", "penta" or "pretalx". Remember to only
126+
# specify one.
127+
128+
# sample schedule configuration for using the json backend.
125129
schedule:
126130
# the backend to pull the schedule from - this can either be a JSON schedule file, or a URL to pull XML from
127131
# Possible values are "json" or "penta". If JSON is chosen, the path to the file must be provided via the
@@ -131,15 +135,30 @@ conference:
131135
# the JSON schema of the JSON schedule format.
132136
scheduleDefinition: "path/to/local/file"
133137

134-
# sample schedule configuration for using the penta backend. When using this configuration ensure that the json
135-
# example above is commented out
138+
# sample schedule configuration for using the penta backend.
136139
# schedule:
137140
# backend: "penta"
138141
# The URL to the XML which is updated with conference information.
139142
# This is read and parsed by the bot during the early stages of
140143
# setting up the conference.
141144
# scheduleDefinition: "https://fosdem.org/2021/schedule/xml"
142145

146+
# sample schedule configuration for using the pretalx backend.
147+
# schedule:
148+
# backend: "pretalx"
149+
# The format the scheduleDefinition is in. Use "pretalx" if you are loading the
150+
# JSON export from pretalx directly, or "penta" if the schema is in penta format.
151+
# scheduleFormat: "penta"|"pretalx"
152+
# The URL to the XML which is updated with conference information.
153+
# This is read and parsed by the bot during the early stages of
154+
# setting up the conference.
155+
# scheduleDefinition: "https://fosdem.org/2021/schedule/xml"
156+
# The endpoint to reach the base API path of the conference.
157+
# pretalxApiEndpoint: "https://pretalx.example.com/api/events/example-2021/"
158+
# Access token for accessing the Pretalx API
159+
# pretalxAccessToken: "secret!"
160+
161+
143162
# The timezone that the the bot's database is operating off of.
144163
timezone: "Europe/Brussels"
145164

src/backends/pretalx/PretalxBackend.ts

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ import * as path from "path";
2222
import { LogService } from "matrix-bot-sdk";
2323
import { PretalxSchema as PretalxData, parseFromJSON } from "./PretalxParser";
2424
import { readFile, writeFile } from "fs/promises";
25-
import { PretalxApiClient, PretalxSpeaker, PretalxTalk } from "./PretalxApiClient";
25+
import { PretalxApiClient } from "./PretalxApiClient";
26+
import { PentabarfParser } from "../penta/PentabarfParser";
2627

2728
export class PretalxScheduleBackend implements IScheduleBackend {
28-
private speakerCache = new Map<string, PretalxSpeaker>();
2929
private readonly apiClient: PretalxApiClient;
3030
private constructor(
3131
private readonly cfg: IPretalxScheduleBackendConfig,
@@ -41,23 +41,23 @@ export class PretalxScheduleBackend implements IScheduleBackend {
4141
}
4242

4343
private static async loadConferenceFromCfg(dataPath: string, cfg: IPretalxScheduleBackendConfig, prefixCfg: IPrefixConfig, allowUseCache: boolean): Promise<{data: PretalxData, cached: boolean}> {
44-
let jsonDesc;
44+
let jsonOrXMLDesc;
4545
let cached = false;
4646

4747
const cachedSchedulePath = path.join(dataPath, 'cached_schedule.json');
4848

4949
try {
5050
if (cfg.scheduleDefinition.startsWith("http")) {
5151
// Fetch the JSON track over the network
52-
jsonDesc = await fetch(cfg.scheduleDefinition).then(r => r.text());
52+
jsonOrXMLDesc = await fetch(cfg.scheduleDefinition).then(r => r.text());
5353
} else {
5454
// Load the JSON from disk
55-
jsonDesc = await readFile(cfg.scheduleDefinition, 'utf-8');
55+
jsonOrXMLDesc = await readFile(cfg.scheduleDefinition, 'utf-8');
5656
}
5757

5858
// Save a cached copy.
5959
try {
60-
await writeFile(cachedSchedulePath, jsonDesc);
60+
await writeFile(cachedSchedulePath, jsonOrXMLDesc);
6161
} catch (ex) {
6262
// Allow this to fail,
6363
LogService.warn("PretalxScheduleBackend", "Failed to cache copy of schedule.", ex);
@@ -70,7 +70,7 @@ export class PretalxScheduleBackend implements IScheduleBackend {
7070

7171
LogService.error("PretalxScheduleBackend", "Unable to load XML schedule, will use cached copy if available.", e.body ?? e);
7272
try {
73-
jsonDesc = await readFile(cachedSchedulePath, 'utf-8');
73+
jsonOrXMLDesc = await readFile(cachedSchedulePath, 'utf-8');
7474
} catch (e) {
7575
if (e.code === 'ENOENT') {
7676
// No file
@@ -84,8 +84,21 @@ export class PretalxScheduleBackend implements IScheduleBackend {
8484
throw "Double fault whilst trying to load JSON schedule";
8585
}
8686
}
87-
88-
const data = await parseFromJSON(jsonDesc, prefixCfg);
87+
let data: PretalxData;
88+
// For FOSDEM we prefer to use the pentabarf format as it contains
89+
// extra information not found in the JSON format. This may change
90+
// in the future.
91+
if (cfg.scheduleFormat === "pentabarf") {
92+
const pentaData = new PentabarfParser(jsonOrXMLDesc, prefixCfg);
93+
data = {
94+
talks: new Map(pentaData.talks.map(v => [v.id, v])),
95+
auditoriums: new Map(pentaData.auditoriums.map(v => [v.name, v])),
96+
interestRooms: new Map(pentaData.interestRooms.map(v => [v.id, v])),
97+
title: pentaData.conference.title,
98+
}
99+
} else {
100+
data = await parseFromJSON(jsonOrXMLDesc, prefixCfg);
101+
}
89102

90103
return {data, cached};
91104
}

src/backends/pretalx/PretalxParser.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,17 @@ export interface PretalxData {
9292

9393

9494
export interface PretalxSchema {
95+
/**
96+
* room.id -> IInterestRoom
97+
*/
9598
interestRooms: Map<string, IInterestRoom>;
99+
/**
100+
* room.name -> IAuditorium
101+
*/
96102
auditoriums: Map<string, IAuditorium>;
103+
/**
104+
* eventId -> ITalk
105+
*/
97106
talks: Map<string, ITalk>;
98107
title: string;
99108
}

src/config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,12 @@ export interface IPentaScheduleBackendConfig {
127127

128128
export interface IPretalxScheduleBackendConfig {
129129
backend: "pretalx";
130+
/**
131+
* Is the schedule in pentabarf or pretalx format? For legacy reasons
132+
* some conferences prefer "pentabarf" which can contain extensions.
133+
* Defaults to "pretalx".
134+
*/
135+
scheduleFormat?: "pentabarf"|"pretalx";
130136
/**
131137
* HTTP(S) URL to schedule XML.
132138
*/

0 commit comments

Comments
 (0)