Advertisement
RemcoE33

Fifa

Nov 18th, 2022 (edited)
703
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2. * Returns fifa ranking
  3. *
  4. * @param {"2022-08-25"} date
  5. * @return {array} ranking
  6. * @customfunction
  7. */
  8. function FIFA(date) {
  9.   const start = new Date('1985-01-01').getTime()
  10.   const current = new Date(date).getTime()
  11.   const diff = current - start
  12.   const dateId = diff / (1000 * 60 * 60 * 24)
  13.   const url = `https://www.fifa.com/api/ranking-overview?locale=en&dateId=id${dateId}`
  14.  
  15.   const results = []
  16.  
  17.   const request = UrlFetchApp.fetch(url)
  18.   JSON.parse(request.getContentText()).rankings
  19.     .forEach((r, i) => {
  20.       const object = {
  21.         Rank: r.rankingItem.rank,
  22.         Name: r.rankingItem.name,
  23.         Total: r.rankingItem.totalPoints,
  24.         Previous: r.previousPoints,
  25.         Difference: r.previousPoints - r.rankingItem.totalPoints,
  26.         Active: r.rankingItem.active,
  27.         Tag: r.tag.text
  28.       }
  29.  
  30.       if (i === 0) {
  31.         results.push(Object.keys(object))
  32.       }
  33.  
  34.       results.push(Object.values(object))
  35.     })
  36.  
  37.   return results
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement