How to have your own soccer results and statistics system with Free Software

All football lovers like to be informed, we want to know the statistics and results of our favorite teams, at the moment there is a lot of information at the level of Football Teams since the Copa America Centenario and the Eurocup are being played, so I came up with my own soccer scores and stats script. euro2016

Our friend jokecamp It has a fairly advanced review on open source football Apis, so getting the information from was a bit simple for me, in general we know of six development / data hosted on github and two Free api that allow us to access data of the most beautiful sport in the world and are:

  • Open Source data on github
    • openfootball - football.db
    • jokecamp / FootballData
    • soccerstats.us
    • engsoccerdata
    • awesome-football
    • soccer-cli
  • Free API
    • football-data.org (RESTful API)
    • Sports Open Data (Italian Serie A)

I will review each of them, because jokecamp He has already done a great review, which has helped me to start this path more easily and in this way meet the objective that I set at the beginning. Although he anticipated that for this specific case select football-data.org a great API that created Daniel Freitag, also that I will use php, the well-known LAMP environment and some free classes.

Without further ado let's talk about each of the data and free Apis that we have to extract information regarding football:

  • openfootball - football.db: It is a free and open source database, which is available to all football fans, it is composed of historical data, game schedules, teams and players, it is the union of many data and many collaborators. Its creator Gerald Bauer to creator is great dating with the firm intention of becoming the largest open data in the history of football.

An example of the data that can be obtained from this repository we have:

[Sat Aug/16]
  12.45  Manchester United    1-2  Swansea City
  15.00  Leicester City       2-2  Everton FC
  15.00  Queens Park Rangers  0-1  Hull City
  15.00  Stoke City           0-1  Aston Villa

Similarly, openfootball It is made up of the following repositories:

  1. https://github.com/footballcsv
  2. https://github.com/openfootball
  3. https://github.com/rsssf
  4. https://github.com/footballdata
  • jokecamp / FootballData: It is a database made by jokecamp and that allows access to your information either by downloading your data through CSV or with JSON requests. This database is oriented to the Premier League, but it also has a lot of information about the EuroCup.
  • soccerstats.usIt is a database that includes multiple Github repositories, in which data from multiple World leagues are disclosed, in addition to all the world soccer championships. The database analyzer is written in Python and apparently extracts information from the Rec.Sport.Soccer Statistics Foundation (RSSSF).
  • engsoccerdata: It is a database that includes a lot of information about the English Leagues and Championships, in the same way there are data from European Leagues such as (Spain, Germany, Italy and Holland). It is a csv file that has all the information and is constantly updated.
  • awesome-football: It is a large collection of soccer data (national and international teams, clubs, match schedules, players, stadiums among others). It is made up of a list of repositories
  • soccer-cli: This without a doubt must be the favorite for console lovers. All football results from your terminal, thanks to the wonders of python.
  • Sports Open Data: It is an api created in 2015 by Paolo Riva and Riccardo Quatra, to make up for the lack of specialized data of the Italian League and to make it totally free. This excellent API provides us with a JSON REST API, which gives us the possibility to consult, analyze and manage the data stored in the Sports Open Data database. This organization's motto is "Free data created by users for users."
  • football-data.org: It is a magnificent RESTful API that contains a lot of data that is constantly updated. You can buy a Free API KEY just by registering which will also give you CORS support. Without a doubt, it is an extremely complete and mature APi with a great job from its creator, many services and applications already include it as a reference for their services.

The possibility of having updated, organized data, with quick and easy access, makes it one of the best Free APIs regarding Football, in addition, football-data has excellent documentation, which allows your learning line to be very fast.

Among the functionalities that it offers us we have:

/soccerseasons/
/soccerseasons/{id}/ranking
/soccerseasons/{id}/fixtures
/fixtures
/soccerseasons/{id}/teams
/teams/{id}
/teams/{id}/fixtures/

Some examples of the calls offered by this API are:

Example of JSON output for Football Team information:

{
   "_links":{
      "self":{
         "href":"http://api.football-data.org/v1/teams/5"
      },
      "fixtures":{
         "href":"http://api.football-data.org/v1/teams/5/fixtures"
      },
      "players":{
         "href":"http://api.football-data.org/v1/teams/5/players"
      }
   },
   "name":"FC Bayern München",
   "code":"FCB",
   "shortName":"Bayern",
   "squadMarketValue":"559,100,000 €",
   "crestUrl":"http://upload.wikimedia.org/wikipedia/commons/c/c5/Logo_FC_Bayern_München.svg"
}

Once this review is done for each of the APIs and Datas that I have known in the world of Free Software, we get down to work to have our simple and exemplary PHP script that allows us to see some data from our favorite teams and events.

The first step is install LAMP but you can also use as a web server, you must have a text editor on hand, you know I like it sublime text Although it is not free, it works on Linux but you are free to use whatever you want nano, notepadqq, atom, scribes among others.

I am going to help myself from a bookstore that I just met phplib-football-data and that it has a basis for communication with football-data, I'll be honest, before I started writing this article I thought it would be more complicated but this library has made my life very easy, so we will only explain the example that they offer us and we will add some extra for educational purposes.

The first step we are going to do is clone the repository git of this bookstore.

git clone git://github.com/dfrt82/phplib-football-data.git

We locate ourselves in the library folder and edit the config.ini file with the KEY API that we obtain when we register in football-data and that reaches our mail.

cd phplib-football-data/
sudo subl3 config.ini

baseUri = 'http://api.football-data.org/v1/';
authToken = 'YOUR_AUTH_TOKEN';

This configuration file will later allow us to communicate the API with our application.

This Sample Library is made up of 5 important files.

  • config.ini: Which saves the API information and which in this step we have already edited.
  • FootballData.php: This service class encapsulates the football-data.org REST API. In other words, it builds communication between the application and the API, it also contains several methods that will allow us to consult various data from the API, such as the entire season of a specific league.
  • Socceroason.php: This class implements the calls related to the information of the matches and the leagues.
  • Team.php: This class implements the calls related to the information of the teams.
  • index.php: What is the main class and the one that calls each of the methods that are implemented in the classes explained above. Basically it is the class that we must touch if we want to change the data to be displayed, for our example we will take the initial structure and simply adapt it to the EuroCup.

Eurocup

With this small modification that I made, we can already have the results of Euro 2016, but without a doubt we can get more creative and add functionalities, cycles, queries to other api among other things, which I will surely show you later. At the moment I hope they show us their creations.


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Peter Sanz said

    Hi, I've been reading your blog, and it seems to me that the page you mention football-data.org looks good for a web service project that we are designing. A big question that arises to me and that I have not been able to clarify from what I have read is: how up-to-date is the data on football-data.org, I give you an example of what I mean:

    Weekend, Barcelona - Real Madrid game, let's say the game ends at 22:00 on a Saturday night with 2-2. So, would you know how to clarify for me when this result would be available to make a request to the API and be able to use that info in the web service?

    The type of service we are designing is not that it requires information in real time, but if the results of the day in question are available days or weeks after they are produced, then it would not be interesting for us.

    A greeting.
    /Peter.

  2.   The Web Developer said

    This is extremely interesting Luigys, I don't understand how Google doesn't have your content higher up since I've had a hard time finding quality references on sports APIs. As the fellow below says, Football-Data looks very good. Thanks a lot.