The world cup is the biggest sporting event on the planet. During the last world cup in 2010, 3.2 billion people watched at least one of the games. As I know, many groups are going to ‘make it interesting’ by placing bets on the results, I thought it would be good to have all the data on a spreadsheet. Google sheets are ideal for that as they offer a great ability to share, comment and ‘play’ with the data. You can see the demo spreadsheet: http://goo.gl/ZjdfqE and fork the code from: https://github.com/greenido/WorldCup
For now, we are fetching the info from these end points:
and they are updated every minute.
Code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // | |
| function fetchAll() { | |
| var url = "http://worldcup.sfg.io/matches"; | |
| fetchScores("ALL", url); | |
| } | |
| // | |
| function fetchScoresToday() { | |
| var url = "http://worldcup.sfg.io/matches/today"; | |
| fetchScores("Today", url); | |
| } | |
| // | |
| // Fetch the scores and push them to the sheet | |
| // | |
| function fetchScores(sheetname, url) { | |
| var response = UrlFetchApp.fetch(url); | |
| var rawData = JSON.parse(response.getContentText()); | |
| var data = new Array(); | |
| for (i in rawData){ | |
| var curObj = new Object(); | |
| curObj.match_number = rawData[i].match_number; | |
| curObj.location = rawData[i].location; | |
| var tmpDate = rawData[i].datetime; | |
| tmpDate = tmpDate.replace("\.000", ""); | |
| curObj.date = (tmpDate); | |
| curObj.status = rawData[i].status; | |
| curObj.winner = rawData[i].winner; | |
| curObj.match_number = rawData[i].match_number; | |
| curObj.match_number = rawData[i].match_number; | |
| curObj.htcountry = rawData[i].home_team.country; | |
| curObj.htcode = rawData[i].home_team.code; | |
| curObj.htgoals = rawData[i].home_team.goals; | |
| curObj.atcountry = rawData[i].home_team.country; | |
| curObj.atcode = rawData[i].home_team.code; | |
| curObj.atgoals = rawData[i].home_team.goals; | |
| data.push(curObj); | |
| } | |
| var ss = SpreadsheetApp.getActiveSpreadsheet(); | |
| var allSheet = ss.getSheetByName(sheetname); | |
| ss.toast("Yep! We are now inserting "+data.length+" rows into " + sheetname); | |
| setRowsData(allSheet, data); | |
| } |
Improvements Ideas
- Integration with BigQuery to give more stats on each match vs historic worlds cap.
- Fetch more data (e.g. bets, weather conditions to help find formula(s) to make prediction.
- Create a UI that will merge: http://fivethirtyeight.com/interactives/world-cup/ and #1 outputs.
Special thanks to the good people of softwareforgood.com who created the API.
Btw, if you have a cool idea for projects that will be based on this spreadsheet… Please share.
Discover more from Ido Green
Subscribe to get the latest posts sent to your email.