Skip to content

Commit

Permalink
Add support for pulling in penta format schemas into the pretalx back…
Browse files Browse the repository at this point in the history
…end.
  • Loading branch information
Half-Shot committed Jan 4, 2024
1 parent a22aba4 commit 9650d1b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 11 deletions.
23 changes: 21 additions & 2 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ conference:
name: "FOSDEM 2021"


# Schema may either be "json", "penta" or "pretalx". Remember to only
# specify one.

# sample schedule configuration for using the json backend.
schedule:
# the backend to pull the schedule from - this can either be a JSON schedule file, or a URL to pull XML from
# Possible values are "json" or "penta". If JSON is chosen, the path to the file must be provided via the
Expand All @@ -131,15 +135,30 @@ conference:
# the JSON schema of the JSON schedule format.
scheduleDefinition: "path/to/local/file"

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

# sample schedule configuration for using the pretalx backend.
# schedule:
# backend: "pretalx"
# The format the scheduleDefinition is in. Use "pretalx" if you are loading the
# JSON export from pretalx directly, or "penta" if the schema is in penta format.
# scheduleFormat: "penta"|"pretalx"
# The URL to the XML which is updated with conference information.
# This is read and parsed by the bot during the early stages of
# setting up the conference.
# scheduleDefinition: "https://fosdem.org/2021/schedule/xml"
# The endpoint to reach the base API path of the conference.
# pretalxApiEndpoint: "https://pretalx.example.com/api/events/example-2021/"
# Access token for accessing the Pretalx API
# pretalxAccessToken: "secret!"


# The timezone that the the bot's database is operating off of.
timezone: "Europe/Brussels"

Expand Down
31 changes: 22 additions & 9 deletions src/backends/pretalx/PretalxBackend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ import * as path from "path";
import { LogService } from "matrix-bot-sdk";
import { PretalxSchema as PretalxData, parseFromJSON } from "./PretalxParser";
import { readFile, writeFile } from "fs/promises";
import { PretalxApiClient, PretalxSpeaker, PretalxTalk } from "./PretalxApiClient";
import { PretalxApiClient } from "./PretalxApiClient";
import { PentabarfParser } from "../penta/PentabarfParser";

export class PretalxScheduleBackend implements IScheduleBackend {
private speakerCache = new Map<string, PretalxSpeaker>();
private readonly apiClient: PretalxApiClient;
private constructor(
private readonly cfg: IPretalxScheduleBackendConfig,
Expand All @@ -41,23 +41,23 @@ export class PretalxScheduleBackend implements IScheduleBackend {
}

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

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

try {
if (cfg.scheduleDefinition.startsWith("http")) {
// Fetch the JSON track over the network
jsonDesc = await fetch(cfg.scheduleDefinition).then(r => r.text());
jsonOrXMLDesc = await fetch(cfg.scheduleDefinition).then(r => r.text());
} else {
// Load the JSON from disk
jsonDesc = await readFile(cfg.scheduleDefinition, 'utf-8');
jsonOrXMLDesc = await readFile(cfg.scheduleDefinition, 'utf-8');
}

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

LogService.error("PretalxScheduleBackend", "Unable to load XML schedule, will use cached copy if available.", e.body ?? e);
try {
jsonDesc = await readFile(cachedSchedulePath, 'utf-8');
jsonOrXMLDesc = await readFile(cachedSchedulePath, 'utf-8');
} catch (e) {
if (e.code === 'ENOENT') {
// No file
Expand All @@ -84,8 +84,21 @@ export class PretalxScheduleBackend implements IScheduleBackend {
throw "Double fault whilst trying to load JSON schedule";
}
}

const data = await parseFromJSON(jsonDesc, prefixCfg);
let data: PretalxData;
// For FOSDEM we prefer to use the pentabarf format as it contains
// extra information not found in the JSON format. This may change
// in the future.
if (cfg.scheduleFormat === "pentabarf") {
const pentaData = new PentabarfParser(jsonOrXMLDesc, prefixCfg);
data = {
talks: new Map(pentaData.talks.map(v => [v.id, v])),
auditoriums: new Map(pentaData.auditoriums.map(v => [v.name, v])),
interestRooms: new Map(pentaData.interestRooms.map(v => [v.id, v])),
title: pentaData.conference.title,
}
} else {
data = await parseFromJSON(jsonOrXMLDesc, prefixCfg);
}

return {data, cached};
}
Expand Down
9 changes: 9 additions & 0 deletions src/backends/pretalx/PretalxParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,17 @@ export interface PretalxData {


export interface PretalxSchema {
/**
* room.id -> IInterestRoom
*/
interestRooms: Map<string, IInterestRoom>;
/**
* room.name -> IAuditorium
*/
auditoriums: Map<string, IAuditorium>;
/**
* eventId -> ITalk
*/
talks: Map<string, ITalk>;
title: string;
}
Expand Down
6 changes: 6 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ export interface IPentaScheduleBackendConfig {

export interface IPretalxScheduleBackendConfig {
backend: "pretalx";
/**
* Is the schedule in pentabarf or pretalx format? For legacy reasons
* some conferences prefer "pentabarf" which can contain extensions.
* Defaults to "pretalx".
*/
scheduleFormat?: "pentabarf"|"pretalx";
/**
* HTTP(S) URL to schedule XML.
*/
Expand Down

0 comments on commit 9650d1b

Please sign in to comment.