Exemplo n.º 1
0
def get_article(game, date):
    game_id = game.get('gameId')
    recap = nba_data("recap_article", date, game_id)
    recap_paras = recap.get('paragraphs')
    article = "<center><h2> AP Summary </h2></center>"
    for paragraph in recap_paras:
        article += "<p>" + paragraph.get('paragraph') + "</p>"
    return article
Exemplo n.º 2
0
def init(date):
    formatted_date = datetime.strptime(date, '%Y%m%d').strftime('%B %d, %Y')
    dir = "html/" + date + "/"
    if not os.path.exists(dir):
        os.makedirs(dir)
    for game in get_scoreboard(date).get('games'):
        boxscore = nba_data("boxscore", date, game.get('gameId'))
        home = get_game_data(game, 'hTeam')
        away = get_game_data(game, 'vTeam')
        article = get_article(game, date)
        city = find_team_city(home.get('team'))
        report = generate_report(boxscore, home, away, article, formatted_date,
                                 city)
        file_name = home.get('team') + "vs" + away.get('team') + date + ".pdf"
        p.from_string(report, file_name)
        os.rename(file_name, dir + file_name)
Exemplo n.º 3
0
def find_team_city(triCode):
    teams = nba_data("teams", 2017).get('league').get('standard')
    for team in teams:
        if team.get('tricode') == triCode:
            return team.get('city')
Exemplo n.º 4
0
def get_scoreboard(date):
    scoreboard = nba_data("scoreboard", date)
    return scoreboard
Exemplo n.º 5
0
        os.makedirs(dir)
    for game in get_scoreboard(date).get('games'):
        boxscore = nba_data("boxscore", date, game.get('gameId'))
        home = get_game_data(game, 'hTeam')
        away = get_game_data(game, 'vTeam')
        article = get_article(game, date)
        city = find_team_city(home.get('team'))
        report = generate_report(boxscore, home, away, article, formatted_date,
                                 city)
        file_name = home.get('team') + "vs" + away.get('team') + date + ".pdf"
        p.from_string(report, file_name)
        os.rename(file_name, dir + file_name)


def get_yesterday_date():
    return (date.today() - timedelta(1)).strftime('%Y%m%d')


def find_team_city(triCode):
    teams = nba_data("teams", 2017).get('league').get('standard')
    for team in teams:
        if team.get('tricode') == triCode:
            return team.get('city')


if __name__ == "__main__":
    calendar = nba_data("calendar")
    date = get_yesterday_date()
    if date in calendar:
        init(date)
Exemplo n.º 6
0
def get_players():
    return nba_data("players", CURRENT_YEAR)
Exemplo n.º 7
0
def get_player_stats(player_id):
    return nba_data("player_game_log", CURRENT_YEAR, player_id)
Exemplo n.º 8
0
from NBAData import nba_data
players = nba_data("players", 2017).get("league").get("standard")


class Player:
    def __init__(self, **kwargs):
        for key, value in kwargs.items():
            if value == "":
                value = 0
            setattr(self, key, value)
        self.player = self.get_player_name(self.personId)

    def get_player_name(self, player_id):
        for each in players:
            if each['personId'] == player_id:
                return each['firstName'] + " " + each['lastName']
        return "N/A"