-
Notifications
You must be signed in to change notification settings - Fork 1
/
live_generator.mjs
67 lines (61 loc) · 1.63 KB
/
live_generator.mjs
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
import { request, gql } from 'graphql-request';
import * as QRcode from 'qrcode'
const competitionId = 'PickeringFallA2023'
const liveEndpoint = 'https://live.worldcubeassociation.org/api';
const fetchLivePersonId = async (compId) => {
const query = gql`
query Competition($competitionId: ID!) {
competition(id: $competitionId) {
id
competitors {
id
name
}
}
}
`;
const data = await request(liveEndpoint, query, {
competitionId: compId,
});
return data.competition.competitors;
}
const fetchLiveCompId = async (name) => {
const query = gql`
query Competitions($filter: String!) {
competitions(filter: $filter, limit: 10) {
id
name
}
}
`;
const data = await request(liveEndpoint, query, {
filter: name,
});
for (const competition of data.competitions) {
if (competition.name === name) {
return competition.id;
}
}
return undefined;
}
const get_wcif = async () => {
const response = await fetch(`https://worldcubeassociation.org/api/v0/competitions/${competitionId}/wcif/public`);
const data = await response.json();
return data;
}
const generateQR = async (text) => {
try {
console.log(await QRcode.toString(text))
} catch (err) {
console.error(err)
}
}
const wcif = await get_wcif();
const liveCompId = await fetchLiveCompId(wcif.name);
const persons = await fetchLivePersonId(liveCompId);
console.log(persons);
for (const person of persons) {
const liveURL = `https://live.worldcubeassociation.org/competitions/${liveCompId}/competitors/${person.id}`
console.log(person.name);
await generateQR(liveURL);
}