0.0.2 • Published 5 years ago

open-fpl v0.0.2

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

Open FPL

Open FPL is an npm package for Premier League data which are mostly used for Fantasy Premier League (FPL). This package returns JSON data which comes from official Premier League API in a more organized and more readable format.

Installation

npm install open-fpl

Getting Started

List of functions:

###GetCurrentGameWeek( callback ) Description: Returns a JSON object containing the Gameweek ID and all the match fixtures with team names for the current Gameweek inside the callback function.

const {gameweek} =  require('open-fpl');
gameweek.GetCurrentGameWeek((err, data) => {
        if(err){
            console.log(err);
            return;
        }
        console.log(data);
    });

Returned Data :

{
"gameweek": 24,
"fixture": [
        {
            "id": 231,
            "kickoff_time_formatted": "29 Jan 19:45",
            "started": true,
            "event_day": 1,
            "deadline_time": "2019-01-29T18:45:00Z",
            "deadline_time_formatted": "29 Jan 18:45",
            "stats": [ ],
            "team_h_difficulty": 2,
            "team_a_difficulty": 4,
            "code": 987823,
            "kickoff_time": "2019-01-29T19:45:00Z",
            "team_h_score": 2,
            "team_a_score": 1,
            "finished": true,
            "minutes": 90,
            "provisional_start_time": false,
            "finished_provisional": true,
            "event": 24,
            "team_a": {
                "id": 5,
                "name": "Cardiff"
            },
            "team_h": {
                "id": 1,
                "name": "Arsenal"
            }
        },
        .,
        .,
        .
    ]
}

###GetGameWeekById( id, callback ) Description : Returns a JSON object containing the Gameweek ID and all the match fixtures with team names for the given Gameweek ID in the callback function.

const {gameweek} =  require('open-fpl');

// here 20 is the id of the gameweek 
gameweek.GetGameWeekById(20, (err, data) => {
        if(err){
            console.log(err);
            return;
        }
        console.log(data);
    });

Return Response Example (JSON): This is an example for Gameweek 20.

{
"gameweek": "20",
"fixture": [
        {
            "id": 191,
            "kickoff_time_formatted": "29 Dec 15:00",
            "started": true,
            "event_day": 1,
            "deadline_time": "2018-12-29T14:00:00Z",
            "deadline_time_formatted": "29 Dec 14:00",
            "stats": [],
            "team_h_difficulty": 3,
            "team_a_difficulty": 3,
            "code": 987782,
            "kickoff_time": "2018-12-29T15:00:00Z",
            "team_h_score": 1,
            "team_a_score": 0,
            "finished": true,
            "minutes": 90,
            "provisional_start_time": false,
            "finished_provisional": true,
            "event": 20,
            "team_a": {
                "id": 8,
                "name": "Everton"
            },
            "team_h": {
                "id": 3,
                "name": "Brighton"
            }
        },
       .,
       .,
       .
    ]
}

###GetAllTeams( callback ) Description : Returns a JSON object containing an array of all teams and their details in the callback function.

const {teams} =  require('open-fpl');

teams.GetAllTeams((err, data) => {
        if(err){
            console.log(err);
            return;
        }
        console.log(data);
        res.send(data);
    });

Returned Data :

[
    {
        "id": 1,
        "current_event_fixture": [
            {
                "is_home": false,
                "day": 9,
                "event_day": 1,
                "month": 2,
                "id": 254,
                "opponent": 10
            }
        ],
        "next_event_fixture": [
            {
                "is_home": true,
                "day": 24,
                "event_day": 3,
                "month": 2,
                "id": 261,
                "opponent": 16
            }
        ],
        "name": "Arsenal",
        "code": 3,
        "short_name": "ARS",
        "unavailable": false,
        "strength": 4,
        "position": 0,
        "played": 0,
        "win": 0,
        "loss": 0,
        "draw": 0,
        "points": 0,
        "form": null,
        "link_url": "",
        "strength_overall_home": 1290,
        "strength_overall_away": 1330,
        "strength_attack_home": 1240,
        "strength_attack_away": 1270,
        "strength_defence_home": 1310,
        "strength_defence_away": 1340,
        "team_division": 1
    },
    .,
    .,
    .
    
]

###GetTeamById( id, callback ) Description : Returns a JSON object containing the team details for the given team ID in the callback function.

const {teams} =  require('open-fpl');
// here 1 is the team id
teams.GetTeamById( 1 , (err, data) => {
        if(err){
            console.log(err);
            return;
        }
        console.log(data);
    });

Return Response Example (JSON): This is an example for team with id : 1.

{
        "id": 1,
        "current_event_fixture": [
            {
                "is_home": false,
                "day": 9,
                "event_day": 1,
                "month": 2,
                "id": 254,
                "opponent": 10
            }
        ],
        "next_event_fixture": [
            {
                "is_home": true,
                "day": 24,
                "event_day": 3,
                "month": 2,
                "id": 261,
                "opponent": 16
            }
        ],
        "name": "Arsenal",
        "code": 3,
        "short_name": "ARS",
        "unavailable": false,
        "strength": 4,
        "position": 0,
        "played": 0,
        "win": 0,
        "loss": 0,
        "draw": 0,
        "points": 0,
        "form": null,
        "link_url": "",
        "strength_overall_home": 1290,
        "strength_overall_away": 1330,
        "strength_attack_home": 1240,
        "strength_attack_away": 1270,
        "strength_defence_home": 1310,
        "strength_defence_away": 1340,
        "team_division": 1
    }

###GetTeamByName( name, callback ) Description : Returns a JSON object containing the team details for the given team name in the callback function.

const {teams} =  require('open-fpl');
// here 1 is the team id
teams.GetTeamByName( 'Arsenal' , (err, data) => {
        if(err){
            console.log(err);
            return;
        }
        console.log(data);
    });

Return Response Example (JSON): This is an example for team 'Arsenal'.

{
        "id": 1,
        "current_event_fixture": [
            {
                "is_home": false,
                "day": 9,
                "event_day": 1,
                "month": 2,
                "id": 254,
                "opponent": 10
            }
        ],
        "next_event_fixture": [
            {
                "is_home": true,
                "day": 24,
                "event_day": 3,
                "month": 2,
                "id": 261,
                "opponent": 16
            }
        ],
        "name": "Arsenal",
        "code": 3,
        "short_name": "ARS",
        "unavailable": false,
        "strength": 4,
        "position": 0,
        "played": 0,
        "win": 0,
        "loss": 0,
        "draw": 0,
        "points": 0,
        "form": null,
        "link_url": "",
        "strength_overall_home": 1290,
        "strength_overall_away": 1330,
        "strength_attack_home": 1240,
        "strength_attack_away": 1270,
        "strength_defence_home": 1310,
        "strength_defence_away": 1340,
        "team_division": 1
    }
  • This documentation will be updated soon with more functions. Cheers!