Jump to content

User:Habst/getWaTour.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// <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>