Placing animations by script

I have a 3d model with a rig and animation and I have a spreedcheet with multiple 1’s and 0’s.
Each data point represents a frame in the final animation.
I want the model to start the rig animation at a 1 and have it end the moment the next 1 appears in the data.
For example: 10000001 is 8 frames of the final animation and the rig animation will play in those 8 frames.
If we have: 10001 the rig animation will play faster (5 frames).
If we have 10000001000000100001 the animation will play 4 times at different speeds.
I don’t have a good idea how to do this, or what method I should try or if its even possible with the blender api.
Help or a general starting point would be great. Thanks!