lets say I'm making requests to an API query which returns a variable number of track ids:
ids = spotipy.get_tracks() # from 10 to 100 ids
but the API has a limit of, say, 50 requests per call. If it surpasses the limit, it will generate an error.
So my current workaround is to limit the calls using random.sample()
, like so:
tracks = random.sample(ids, 50)
however, if the query returns LESS
than 50 results, it will also generate an error.
how do I limit the number of calls to a maximum of 50, using random.choice()
?
or is there a better solution?
Aucun commentaire:
Enregistrer un commentaire