Created
March 17, 2019 19:48
-
-
Save fatihbaltaci/004d46e002fbd80606d8f2d0b6019214 to your computer and use it in GitHub Desktop.
Deletes files from Slack with Python 3
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
import requests | |
TOKEN = "<YOUR_TOKEN>" | |
def delete(_response): | |
for f in _response.json()["files"]: | |
print("Deleting file " + f["name"] + "...") | |
delete_url = 'https://slack.com/api/files.delete' | |
res = requests.post(delete_url, data={ | |
"token": TOKEN, | |
"file": f["id"], | |
"set_active": "true", | |
"_attempts": "1"}) | |
if res.json()['ok']: | |
print("Deleted") | |
else: | |
print("Not deleted. Reason: " + res.json()['error']) | |
if __name__ == '__main__': | |
files_list_url = 'https://slack.com/api/files.list' | |
#data = {"token": TOKEN, "user": "<USER_ID>"} # Delete files from specific user. To get user id: https://gist.github.com/fatihbaltaci/8dbb3765db6325ed045eb557c45a01c4 | |
data = {"token": TOKEN} | |
response = requests.post(files_list_url, data=data) | |
print("--------- FILES LIST: ----------------") | |
for res in response.json()['files']: | |
print(res['name'] + " - " + res['permalink']) | |
delete(response) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment