Last active
November 6, 2019 05:03
-
-
Save csghone/32f61d6ba50f08dde5978f4ee77c8da9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| #!/usr/bin/env python3 | |
| # Usage: python3 download_files_from_slack.py <URL> | |
| import sys | |
| import re | |
| import requests | |
| url = " ".join(sys.argv[1:]) | |
| token = 'SLACK_TOKEN' | |
| resp = requests.get(url, headers={'Authorization': 'Bearer %s' % token}) | |
| headers = resp.headers['content-disposition'] | |
| fname = re.findall("filename=(.*?);", headers)[0].strip("'").strip('"') | |
| assert not os.path.exists(fname), print("File already exists. Please remove/rename and re-run") | |
| out_file = open(fname, mode="wb+") | |
| out_file.write(resp.content) | |
| out_file.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment