Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Returns fifa ranking
- *
- * @param {"2022-08-25"} date
- * @return {array} ranking
- * @customfunction
- */
- function FIFA(date) {
- const start = new Date('1985-01-01').getTime()
- const current = new Date(date).getTime()
- const diff = current - start
- const dateId = diff / (1000 * 60 * 60 * 24)
- const url = `https://www.fifa.com/api/ranking-overview?locale=en&dateId=id${dateId}`
- const results = []
- const request = UrlFetchApp.fetch(url)
- JSON.parse(request.getContentText()).rankings
- .forEach((r, i) => {
- const object = {
- Rank: r.rankingItem.rank,
- Name: r.rankingItem.name,
- Total: r.rankingItem.totalPoints,
- Previous: r.previousPoints,
- Difference: r.previousPoints - r.rankingItem.totalPoints,
- Active: r.rankingItem.active,
- Tag: r.tag.text
- }
- if (i === 0) {
- results.push(Object.keys(object))
- }
- results.push(Object.values(object))
- })
- return results
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement