Skip to content

Instantly share code, notes, and snippets.

@fenech
Created March 22, 2018 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fenech/fd24e29e7bc1a6b719a50308a13ad226 to your computer and use it in GitHub Desktop.
Save fenech/fd24e29e7bc1a6b719a50308a13ad226 to your computer and use it in GitHub Desktop.
Delete large files from Slack
#!/usr/bin/env python3
import requests
import json
token = '' # your token here
limit = 1024 * 1024 # 1MB
def list_files(page=1):
params = { 'token': token, 'page': page }
response = requests.get('https://slack.com/api/files.list', params=params)
return json.loads(response.text)
response = list_files()
for page in range(response['paging']['pages'] + 1):
response = list_files(page)
for file in filter(lambda file: file['size'] > limit, response['files']):
body = { 'token': token, 'file': file['id'] }
response = requests.post('https://slack.com/api/files.delete', body)
status = json.loads(response.text)
if status['ok']:
print("deleted {}".format(file['name']))
else:
print("failed to delete {}: {}".format(file['name'], status['error']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment