Skip to content

Instantly share code, notes, and snippets.

@omgmog
Created May 11, 2018 13:50
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 omgmog/d49e026ca1164e1da0062740627c052a to your computer and use it in GitHub Desktop.
Save omgmog/d49e026ca1164e1da0062740627c052a to your computer and use it in GitHub Desktop.
Get the 10 biggest files in a Slack workspace.
from slacker import Slacker
import itertools
from hurry.filesize import size
slack = Slacker('<API KEY>')
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)
files = biggest_first[:10]
for file in files:
ftitle = file[u'title']
fsize = file[u'size']
furl = file[u'permalink']
print("%s: %s - %s" % (ftitle, size(fsize), furl))
# To delete e.g.
# slack.files.delete(file['id'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment