Created
March 22, 2018 13:57
-
-
Save fenech/fd24e29e7bc1a6b719a50308a13ad226 to your computer and use it in GitHub Desktop.
Delete large files from Slack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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