Skip to content

Instantly share code, notes, and snippets.

@hlian
Forked from shauns/slack.py
Created July 3, 2017 18:54
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 hlian/4cbd614dc3d5388d20847e9ca71786ee to your computer and use it in GitHub Desktop.
Save hlian/4cbd614dc3d5388d20847e9ca71786ee to your computer and use it in GitHub Desktop.
Deleting and listing slack files, sorting by size
from slacker import Slacker
import itertools
slack = Slacker('<API TOKEN>')
pages = slack.files.list(page=1).body['paging']['pages']
all_the_files = list(itertools.chain(*[slack.files.list(page=i).body['files'] for i in range(1,pages + 1)]))
biggest_first = sorted(all_the_files, key=lambda f: f['size'], reverse=True)
# To delete e.g. the biggest file
slack.files.delete(biggest_first[0]['id'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment