appfunctions.js 4.19 KB
// 입력: 팀ID, 리그ID, 시즌 입력,  반환: 경기일정 
function GetGameSchedule(teamID, leagueID, season, eventObj){
    var request = require("request");
    var options = {
    method: 'GET',
    url: 'https://v3.football.api-sports.io/fixtures',
    qs: {team: teamID, league: leagueID, season: season},
    headers: {
        'x-rapidapi-host': 'v3.football.api-sports.io',
        'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191'
    }
    };
    request(options, function (error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
    });
}

// 입력: 리그ID, 시즌(*필수)   반환: 팀 순위 
function GetLeagueStanding(leagueID, season){
    var request = require("request");
    var options = {
    method: 'GET',
    url: 'https://v3.football.api-sports.io/standings',
    qs: {league : leagueID, season: season},
    headers: {
        'x-rapidapi-host': 'v3.football.api-sports.io',
        'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191'
    }
    };
    request(options, function (error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
        let jsonBody = JSON.parse(body);
        console.log(jsonBody);
        console.log(jsonBody.response[0]);
        console.log(jsonBody.response[0].league);
        for(var i = 0; i < 20; i++){
            console.log(jsonBody.response[0].league.standings[0][i].rank + "|" + jsonBody.response[0].league.standings[0][i].team.name);
        }
        
    });
}

// 입력: 리그ID(*필수), 시즌(*필수),  반환: (선수) 득점 순위
function GetTopScorer(leagueID, season){
    var request = require("request");
    var options = {
    method: 'GET',
    url: 'https://v3.football.api-sports.io/players/topscorers',
    qs: {league : leagueID, season: season},
    headers: {
        'x-rapidapi-host': 'v3.football.api-sports.io',
        'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191'
    }
    };
    request(options, function (error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
    });
}

// 입력: 리그ID(*필수), 시즌(*필수), 반환: 도움 순위
function GetTopAssist(leagueID, season){
    var request = require("request");
    var options = {
    method: 'GET',
    url: 'https://v3.football.api-sports.io/players/topassists',
    qs: {league : leagueID, season: season},
    headers: {
        'x-rapidapi-host': 'v3.football.api-sports.io',
        'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191'
    }
    };
    request(options, function (error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
    });
}

// 입력: 팀ID, 반환: 경기 일정
function GetGameSchedule_teamname(teamID){
    var request = require("request");
    var options = {
    method: 'GET',
    url: 'https://v3.football.api-sports.io/fixtures',
    qs: {team: teamID},
    headers: {
        'x-rapidapi-host': 'v3.football.api-sports.io',
        'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191'
    }
    };
    request(options, function (error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
    });
}

// 입력: 팀ID, 반환: 소속 선수
function GetTeamMembers(teamID){
    var request = require("request");
    var options = {
      method: 'GET',
      url: 'https://v3.football.api-sports.io/players',
      qs: {team: teamID},
      headers: {
        'x-rapidapi-host': 'v3.football.api-sports.io',
        'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191'
      }
    };
    request(options, function (error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
    })    
}

// 입력: 팀ID, 시즌*(필수),   반환: 팀 순위 
function GetTeamStanding(teamID, season){
    var request = require("request");
    var options = {
    method: 'GET',
    url: 'https://v3.football.api-sports.io/standings',
    qs: {team: teamID, season: season},
    headers: {
        'x-rapidapi-host': 'v3.football.api-sports.io',
        'x-rapidapi-key': '526fc70a2e8b315e9a960ac4b4764191'
    }
    };
    request(options, function (error, response, body) {
        if (error) throw new Error(error);
        console.log(body);
    });
}