Skip to content

Commit decc331

Browse files
authored
2026 badges updates (#4644)
1 parent 1f9d26a commit decc331

1 file changed

Lines changed: 38 additions & 34 deletions

File tree

badge-service/main.js

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,21 @@ const fs = require("node:fs");
66
const archiver = require("archiver");
77

88
const EMPTY_BADGES_COUNT = {
9-
ATTENDEE: 70,
10-
SPEAKER: 25,
9+
ATTENDEE: 50,
10+
SPEAKER: 20,
1111
STAFF: 20,
12-
SPONSOR: 30,
12+
SPONSOR: 20 + 45,
1313
KEYNOTER: 6,
14-
DJANGO_GIRLS: 25,
14+
DJANGO_GIRLS: 30,
1515
};
1616

17-
const getAllQuestions = async () => {
18-
const request = await fetch(
19-
"https://tickets.pycon.it/api/v1/organizers/python-italia/events/pyconit2025/questions/",
20-
{
21-
headers: {
22-
Authorization: `Token ${process.env.PRETIX_API_TOKEN}`,
23-
},
24-
},
25-
);
26-
const response = await request.json();
27-
return response.results;
28-
};
17+
const CACHED_ORDER_POSITIONS = {};
2918

3019
const getConferenceRoleForTicketData = async (orderPosition) => {
20+
if (CACHED_ORDER_POSITIONS[orderPosition.id]) {
21+
return CACHED_ORDER_POSITIONS[orderPosition.id];
22+
}
23+
3124
const request = await fetch("https://admin.pycon.it/graphql", {
3225
method: "POST",
3326
headers: {
@@ -46,17 +39,19 @@ const getConferenceRoleForTicketData = async (orderPosition) => {
4639
}`,
4740
variables: {
4841
ticketData: JSON.stringify(orderPosition),
49-
conferenceCode: "pycon2025",
42+
conferenceCode: "pycon2026",
5043
},
5144
}),
5245
});
5346
const response = await request.json();
54-
return response.data.conferenceRoleForTicketData;
47+
CACHED_ORDER_POSITIONS[orderPosition.id] =
48+
response.data.conferenceRoleForTicketData;
49+
return CACHED_ORDER_POSITIONS[orderPosition.id];
5550
};
5651

5752
const getAllOrderPositions = async () => {
5853
let next =
59-
"https://tickets.pycon.it/api/v1/organizers/python-italia/events/pyconit2025/checkinlists/59/positions/";
54+
"https://tickets.pycon.it/api/v1/organizers/python-italia/events/pyconit2026/checkinlists/72/positions/";
6055
const positions = [];
6156
while (next) {
6257
const request = await fetch(next, {
@@ -88,24 +83,19 @@ const createEmptyBadgeOrderPositions = () => {
8883
};
8984

9085
(async () => {
91-
fs.rmSync("generated-badges", { recursive: true });
86+
fs.rmSync("generated-badges", { recursive: true, force: true });
9287
fs.mkdirSync("generated-badges");
9388

89+
const allBadgesCreated = [];
90+
9491
const allOrderPositions = [
9592
...(await getAllOrderPositions()),
9693
...createEmptyBadgeOrderPositions(),
9794
];
9895

99-
const questions = await getAllQuestions();
100-
101-
const pronounsQuestion = questions.find((q) => q.identifier === "SMZHLTGP");
102-
const taglineQuestion = questions.find((q) => q.identifier === "83HY8DTB");
103-
104-
assert(pronounsQuestion);
105-
assert(taglineQuestion);
106-
10796
const browser = await puppeteer.launch({
10897
headless: "new",
98+
args: ["--no-sandbox"],
10999
});
110100
const page = await browser.newPage();
111101
let counter = 0;
@@ -135,17 +125,24 @@ const createEmptyBadgeOrderPositions = () => {
135125

136126
const answers = orderPosition.answers;
137127
let pronouns =
138-
answers.find((a) => a.question === pronounsQuestion.id)?.answer ?? "";
128+
answers.find((a) => a.question_identifier === "SMZHLTGP")?.answer ?? "";
139129

140130
if (pronouns === "--") {
141131
pronouns = "";
142132
}
143133

144134
const tagline =
145-
answers.find((a) => a.question === taglineQuestion.id)?.answer ?? "";
135+
answers.find((a) => a.question_identifier === "83HY8DTB")?.answer ?? "";
146136

147137
const { role, ticketHashid } =
148138
await getConferenceRoleForTicketData(orderPosition);
139+
140+
if (side === "front") {
141+
allBadgesCreated.push({
142+
name: orderPosition.attendee_name,
143+
role,
144+
});
145+
}
149146
return {
150147
name: orderPosition.attendee_name,
151148
pronouns,
@@ -189,10 +186,12 @@ const createEmptyBadgeOrderPositions = () => {
189186

190187
for (const group of chunk(allOrderPositions, 4)) {
191188
for (const side of ["front", "back"]) {
192-
const item1 = await createBadgeData(group[0], side);
193-
const item2 = await createBadgeData(group[1], side);
194-
const item3 = await createBadgeData(group[2], side);
195-
const item4 = await createBadgeData(group[3], side);
189+
const [item1, item2, item3, item4] = await Promise.all([
190+
createBadgeData(group[0], side),
191+
createBadgeData(group[1], side),
192+
createBadgeData(group[2], side),
193+
createBadgeData(group[3], side),
194+
]);
196195

197196
const badgeData =
198197
side === "front"
@@ -217,6 +216,11 @@ const createEmptyBadgeOrderPositions = () => {
217216
counter = counter + 1;
218217
}
219218

219+
fs.writeFileSync(
220+
"badges-created.json",
221+
JSON.stringify(allBadgesCreated, null, 2),
222+
);
223+
220224
await browser.close();
221225
archive.finalize();
222226
})();

0 commit comments

Comments
 (0)