Ejemplo n.º 1
0
subreddit = reddit.subreddit(
    SUBREDDIT_CHOICE
)  # We only want the bot running on this specific subreddit
KEYPHRASE = '!stats '  # Bot responds to this keyphrase only.

for comment in subreddit.stream.comments(
        skip_existing=True
):  # Watch the comment stream on our subreddit of choice
    if KEYPHRASE in comment.body:
        tableBase = "GP|PTS|REB|AST|STL|BLK|TOV|3PM|FG%|FT%\n:--|:--:|:--:|:--:|:--:|:--:|:--:|:--:|:--|:--\n"  # We want to format our response neatly, this is just the formatting convention Reddit uses to create tables.
        N = 0  # N represents the number of games to include in our averages. N = 0 will default to pulling averages for the entire season so far.

        player = comment.body.replace(
            KEYPHRASE, ''
        )  # Get rid of the keyphrase leaving us with the players name and optionally an N value
        player = HumanName(player.translate(str.maketrans('', '', "!?.,'-")))

        if (player.first.isdigit() == True):  # If the user entered a number
            N = player.first
            player.first = player.middle

        if player.suffix == '':  # Player did not enter a suffic (Jr, III etc)
            playerID = findPlayer(obj, player.first, player.last)
        else:
            playerID = findPlayer(obj, player.first,
                                  player.last + " " + player.suffix)

        if playerID != None:
            URL = 'https://stats.nba.com/stats/playerdashboardbylastngames/?measureType=Base&perMode=PerGame&plusMinus=N&paceAdjust=N&rank=N&leagueId=00&season=2019-20&seasonType=Regular+Season&poRound=0&playerId=' + str(
                playerID
            ) + '&outcome=&location=&month=0&seasonSegment=&dateFrom=&dateTo=&opponentTeamId=0&vsConference=&vsDivision=&gameSegment=&period=0&shotClockRange=&lastNGames=' + str(