Twilio – Delete recordings

from this https://www.twilio.com/blog/2016/05/bulk-delete-your-twilio-recordings-with-python.html but updated for new API


from twilio.rest import Client
from datetime import datetime
import os

# Your Account SID from twilio.com/console
account_sid = "SID"
#account_sid = os.environ["TWILIO_ACCOUNT_SID"]
# Your Auth Token from twilio.com/console
auth_token = "TOKEN"
#auth_token = os.environ["TWILIO_AUTH_TOKEN"]
client = Client(account_sid, auth_token)

recordings = client.recordings\
.list(
date_created_before=datetime(2018, 1, 1),
date_created_after=datetime(2016, 1, 1)
)

for record in recordings:
# client.recordings('record.sid').delete()
client.recordings(record.sid).delete()
print("Deletings Recording: ", record.sid)

something was wrong and it kept stalling so I needed to loop it – bash hack.

while true ; do time python3 del_rec.py ; done