Created
April 3, 2017 13:36
-
-
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.
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
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