雅虎!幻想API最大计数?

2024-10-03 21:33:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力获得一个职位的所有可用的球员与JSON返回雅虎!Fantasy API,使用此资源:

http://fantasysports.yahooapis.com/fantasy/v2/game/nfl/players;status=A;position=RB

这个API似乎总是返回最多25个玩家。我也尝试过使用;count=n过滤器,但是如果n比25高,我仍然只能返回25个玩家。有人知道为什么吗?我怎样才能得到更多?在

这是我的代码:

^{pr2}$

Tags: comapigamejsonhttp玩家职位资源
1条回答
网友
1楼 · 发布于 2024-10-03 21:33:51

我确实解决了这个问题。我发现最大的“count”是25,但是“start”参数是这个操作的关键。API似乎为每个播放器附加了一个索引(不管它是如何排序的),“start”参数就是要开始的索引。这可能看起来很奇怪,但我唯一能找到的办法就是让25名球员分批归队。所以我的代码解决方案如下:

from yahoo_oauth import OAuth1

oauth = OAuth1(None, None, from_file='oauth.json', base_url='http://fantasysports.yahooapis.com/fantasy/v2/')

done = False
start = 1
while(not done) :
    uri = 'league/nfl.l.<league>/players;position=RB;status=A;start=%s,count=25' % start

    if not oauth.token_is_valid():
        oauth.refresh_access_token

    response = oauth.session.get(uri, params={'format': 'json'})

    # parse response, get num of players, do stuff

    start += 25

    if numPlayersInResp < 25:
        done = True

相关问题 更多 >