User:Habst/getWaTour.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Habst/getWaTour. |
// <nowiki>
tourType = 'cross-country-tour';
year = '2024/25';
ids = {
'cross-country-tour': {
winnerCol: true,
'2023/24': {id: 3664, Gold: 3983, Silver: 3984, Bronze: 3985},
'2024/25': {id:3664,Gold:3983,Silver:3984,Bronze:3985},
},
'label-road-races': {
2024: {id:3775,Platinum:3722,Gold:3659,Elite:3944,Label:3947},
},
'combined-events-tour': {
'2023/24': {id:3767,Gold:3987,Silver:3988,Bronze:3989},
},
'race-walking-tour': {
'2023/24': {id:3692,Gold:3991,Silver:3992,Bronze:3993},
},
'continental-tour': {
2024: {id:3773,Gold:3781,Silver:3782,Bronze:3783,Challenger:4049},
},
}
meets = await (await fetch("https://graphql-prod-4671.prod.aws.worldathletics.org/graphql", {
"credentials": "omit",
"headers": {
"x-api-key": "da2-xfoozjz6kjenjjqju6gvhqew4e",
},
"body": JSON.stringify({
"operationName": "getMinisiteCalendarEvents",
"query": `query getMinisiteCalendarEvents($competitionGroupId: Int, $competitionSubgroupId: Int, $season: String) {
getMinisiteCalendarEvents(competitionGroupId: $competitionGroupId, competitionSubgroupId: $competitionSubgroupId, season: $season) {
options {
seasons {
id
name
__typename
}
competitionSubgroups {
id
name
count
__typename
}
__typename
}
parameters {
season
competitionGroupId
competitionSubgroupId
__typename
}
results {
id
iaafId
hasResults
hasStartlist
hasApiResults
disciplines
rankingCategory
competitionSubgroup
undeterminedCompetitionPeriod {
status
label
remark
__typename
}
name
venue
country
startDate
endDate
dateRange
__typename
}
__typename
}
}`,
"variables": {
"competitionGroupId": ids[tourType][year].id,
"competitionSubgroupId": 0,
"season": year,
}
}),
"method": "POST",
})).json();
console.log(Object.keys(ids[tourType][year]).filter(k => k !== 'id').map(tier => {
const mtgs = meets.data.getMinisiteCalendarEvents.results.filter(m => m.competitionSubgroup === tier);
return `| colspan="${ids[tourType].winnerCol ? 6 : 4}" align="center" bgcolor="${{
Challenger:'white',
Label:'white',
Elite:'silver',
Platinum:'blue',
}[tier] ?? tier.toLowerCase()}" | '''${tier}''' (${mtgs.length})<ref>{{cite web |title=World Athletics ${tourType} ${tier} {{!}} World Athletics |url=https://worldathletics.org/competitions/world-athletics-${tourType}/calendar-results?season=${year}&competitionSubgroupId=${ids[tourType][year][tier]} |website=worldathletics.org |access-date=${new Date().toLocaleDateString('sv')}}}</ref>\n|-\n` + mtgs.map(m => {
const words = m.name.split(' ').filter((w, i) => {
if (+w === new Date(m.startDate).getFullYear()) return false;
if (w.match(/^[0-9]+(st|nd|rd|th)$/)) return false;
if (w.match(/^[0-9]+(\.|°|º|\.º)$/)) return false;
if (w.match(/^[0-9]+ème$/)) return false;
if (i === 0 && w.match(/^[IVXL]+$/)) return false;
return true;
});
// if (words.join(' ') === 'Meeting de Paris') words.push('Indoor');
let name = words.join(' ');
name = {
Tallinn: 'Combined Events Tour Tallinn',
ISTAF: 'ISTAF Berlin',
'The Hero': 'The Hero!',
'Capital Classic': 'Team Ledger Harcourts Capital Classic',
"Sky's the Limit": "Sky's the Limit Meeting",
'Gouden Spike': 'Gouden Spike Meeting',
'Cork City Sports': 'Cork City Sports International Athletics',
'White Cross': 'International White Cross',
}[name] ?? name;
let city = m.venue.split(', ').slice(1).join(', ').split(' (')[0];
if (!city || (m.country === 'USA' && city.split(' ').length <= 1)) city = m.venue.split(' (')[0];
city = {
Montreuil: 'Montreuil, Seine-Saint-Denis',
Halle: 'Halle (Saale)',
Duszniki: 'Duszniki, Greater Poland Voivodeship',
Cork: 'Cork (city)',
Windsor: 'Windsor, Ontario',
Allonnes: 'Allonnes, Sarthe',
}[city] ?? city;
return `| {{dts|abbr=on|${m.startDate}|format=dm}} || ${['Gold', 'Silver', 'Bronze', 'Challenger', 'Platinum', 'Elite', 'Label'].includes(tier) ? `[[${name}]]` : name} || [[${city}, {{subst:#invoke:Country alias|main|alias=${m.country}}}|${city}]] || {{flagg|cncie|${m.country}}}` + (ids[tourType].winnerCol ? ' || || ' : '');
}).join('\n|-\n')
}).join('\n|-\n'));
// </nowiki>