Getting started
===============

Installation
------------

Before using the ``SkillcornerClient``, you need to install it:

.. code-block:: bash

    pip install --upgrade skillcorner

Now you need to set up your Skillcorner credentials by adding the following variables to your environment:

* SKILLCORNER_USERNAME: Your username
* SKILLCORNER_PASSWORD: Your password

How to use it
-------------

You can instantiate the ``SkillcornerClient`` class like so:

.. code-block:: python

    from skillcorner.client import SkillcornerClient

    client = SkillcornerClient()

Alternative
-----------

If you don't want to set those environment variables you will need to provide your username and password at instantiation. We strongly recommend using environment variables or any other way to avoid having your password in your code.

.. code-block:: python

    import os
    from skillcorner.client import SkillcornerClient

    secret_password = os.getenv('MY_PASSWORD_ENV_VAR')
    client = SkillcornerClient(username='myusername', password=secret_password)

Examples
--------

Seasons
~~~~~~~

Get and print seasons data

.. code-block:: python

    seasons = client.get_seasons()
    pprint(seasons)

Competitions
~~~~~~~~~~~~

Get and print competition data for season 2023-2024 (season id 28)

.. code-block:: python

    competitions = client.get_competitions(params={'season': 28})
    pprint(competitions)

Save competition data to a file

.. code-block:: python

    client.save_competitions(filepath='competitions_23_24.json', params={'season': 28})

Competition editions
~~~~~~~~~~~~~~~~~~~~

Get and print competition editions for FRA Ligue 1 (competition id 3)

.. code-block:: python

    competition_editions = client.get_competition_editions(competition_id=3)
    pprint(competition_editions)

Save competition data to a file

.. code-block:: python

    client.save_competition_editions(competition_id=3, filepath='competition_editions_FRA_Ligue_1.json')

We can also filter on the season using the 'params' parameter

.. code-block:: python

    competition_editions = client.get_competition_editions(competition_id=3, params={'season': 28})
    pprint(competition_editions)

Matches
~~~~~~~

Get and print matches for FRA Ligue 1 2023-2024 (competition edition id 548)

.. code-block:: python

    matches = client.get_matches(params={'competition_edition': 548})
    pprint(matches)

Save matches to a file

.. code-block:: python

    client.save_matches(filepath='matches_FRA_Ligue_1_2023_2024.json', params={'competition_edition': 548})

Match data
~~~~~~~~~~

Get and print match data for FRA Ligue 1 2023-2024 - Clermont Foot vs AS Monaco (match id 1023377)

.. code-block:: python

    match_id = 1023377
    match_data = client.get_match(match_id=match_id)
    pprint(match_data)

Save match data to a file

.. code-block:: python

    client.save_match(match_id=match_id, filepath=f'match_data_{match_id}.json')

Match Tracking Data
~~~~~~~~~~~~~~~~~~~

Get and print match tracking data (if you have access to the match tracking data API)

.. code-block:: python

    match_id = 1023377  # FRA Ligue 1 2023-2024 - Clermont Foot vs AS Monaco
    match_tracking_data = client.get_match_tracking_data(match_id=match_id)
    pprint(match_tracking_data[10000:11000])  # print only the tracking data for frames 10000 to 11000

Save match tracking data to a file

.. code-block:: python

    client.save_match_tracking_data(match_id=match_id, filepath=f'match_tracking_data_{match_id}.json')

Physical Data
~~~~~~~~~~~~~

Get and print physical data for FRA Ligue 1 2023-2024 - OGC Nice (team id 70)

.. code-block:: python

    physical_data = client.get_physical(params={'season': 28, 'team': 70})
    pprint(physical_data)

Save physical data to a file

.. code-block:: python

    client.save_physical(filepath='physical.json', params={'season': 28, 'team': 70})

Teams
~~~~~

Get and print teams for FRA Ligue 1 2023-2024 (competition edition id 548)

.. code-block:: python

    teams = client.get_teams(params={'competition_edition': 548})
    pprint(teams)

Save team data

.. code-block:: python

    client.save_teams(filepath='teams_FRA_Ligue_1_2023_2024.json', params={'competition_edition': 548})

Get and print team data for OGC Nice (team id 70)

.. code-block:: python

    team_id = 70
    team_data = client.get_team(team_id=team_id)
    pprint(team_data)

Save team data

.. code-block:: python

    client.save_team(team_id=team_id, filepath=f'team_{team_id}.json')

Players
~~~~~~~

Get and print players

.. code-block:: python

    players = client.get_players(params={'search': 'barcola'})
    pprint(players)

Get and print player data

.. code-block:: python

    player_id = 68485
    player_data = client.get_player(player_id=player_id)
    pprint(player_data)

Save player data

.. code-block:: python

    client.save_player(player_id=player_id, filepath=f'player_{player_id}.json')
