Removing bad segments through the code

Hello everyone,

I already have time stamps provided for bad segments for my raw file. So rather than going over the entire file for one sample-time at a time, I was wondering if it would be possible to annotate bad segments by directly copying the (bad segment) time stamps in the MNE python code. Is that possible? Is there a function where I can insert the times of occurrence of bad segments directly rather than going through the GUI and removing each segments manually?)
For example, attached is the time of occurence of bad segments in the file:

you can create an Annotations object programmatically (with code) and then attach it to the Raw object (see here: Annotating continuous data β€” MNE 0.24.1 documentation). If you want the annotations to later cause rejection of epochs that overlap the annotations, make sure the β€œdescription” field of each annotation begins with "bad_".