Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # List all files on Slack bigger than set value
- # Modified from: http://www.shiftedup.com/2014/11/13/how-to-bulk-remove-files-from-slack
- # https://api.slack.com/custom-integrations/legacy-tokens
- _token = "PASTE YOUR TOKEN HERE"
- # in MiB
- _min_file_size = 10
- import requests
- import json
- import calendar
- from datetime import datetime, timedelta
- cnt = 0
- def printfile(f):
- global cnt
- cnt = cnt + 1
- id = f["id"]
- size = f["size"]
- type = f["pretty_type"]
- title = f["title"]
- size = f["size"]
- size = (int)(size/1024/1024)
- # Only "hosted" files have size
- if size < _min_file_size:
- return
- print "%4i: %s %4imb %20s %s" % (cnt, id, size, type, title)
- if __name__ == '__main__':
- page = 1
- while page < 100:
- files_list_url = 'https://slack.com/api/files.list'
- date = str(calendar.timegm((datetime.now() + timedelta(-30))
- .utctimetuple()))
- data = {"token": _token, "ts_to": date, "page": page, "count": 500}
- response = requests.post(files_list_url, data = data)
- if len(response.json()["files"]) == 0:
- break
- for f in response.json()["files"]:
- printfile(f)
- page = page + 1
- print "DONE!"
Add Comment
Please, Sign In to add comment