Skip to content

Instantly share code, notes, and snippets.

@maxhelskens
Created April 3, 2017 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maxhelskens/b57165be58159879e66f37b2c44329fd to your computer and use it in GitHub Desktop.
Save maxhelskens/b57165be58159879e66f37b2c44329fd to your computer and use it in GitHub Desktop.
Python script to bulk remove all files older than 60 days. NOTE: insert your own slack token.
import requests
import json
import datetime
import time
# You can get your own token at: https://api.slack.com/custom-integrations/legacy-tokens
TOKEN = ''
# Timestamp of 60 days ago
ts_to = time.time() - 60 * 24 * 60 * 60
# Number of files to return
count = 200
url='https://slack.com/api/files.list?token=' + TOKEN + '&ts_to=' + str(ts_to) + '&count=' + str(count)
response = requests.get(url)
response = response.json()
files = response['files']
for i in range(0, len(files)):
file_id = files[i]['id']
delete_url = 'https://slack.com/api/files.delete?token=' + TOKEN + '&file=' + str(file_id)
response = requests.get(delete_url)
response = response.json()
print 'delete status ' + str(files[i]['name']) + ' :' + str(response['ok'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment