Created
May 11, 2018 13:50
-
-
Save omgmog/d49e026ca1164e1da0062740627c052a to your computer and use it in GitHub Desktop.
Get the 10 biggest files in a Slack workspace.
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
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