Reputation: 105
How do you track how many queries are left in the rate-limit-bucket for stream-info? I want to slow/pause queries to not exceed the limit. In TwitchAPI, I've found twitchAPI.helper.RateLimitBucket
but have no idea how to use it to track stream-information requests.
As I understand, query limits for different requests are: Stream Requests (100?), General Requests (app/user) (800), and JWTs Extension viewer(?): (30). Please correct me if I'm wrong on any of those.
This code queries and waits, but doesn't know how many queries are available in the bucket. I use user-queries instead of stream-queries for ease of example, but care about steam queries.
import time, asyncio, twitchAPI
async def init_api(user, key):
return await twitchAPI.twitch.Twitch(user, key)
async def get_user_data(api, channel_name):
return await twitchAPI.helper.first(api.get_users(logins=channel_name))
async def get_stream_data(api, channel_name):
return await twitchAPI.helper.first(api.get_streams(user_login=channel_name))
if __name__ == "__main__":
user = 'ABCD'
key = 'EFGH'
channel = "test_channel"
twitch_api = asyncio.run(init_api(user, key))
while True:
stream_dict = asyncio.run(get_user_data(twitch_api, channel)).__dict__
print("Stream Data:", stream_dict)
time.sleep(5)
Upvotes: 0
Views: 41