-
-
Save thesoftwarejedi/d78af9ee12b7f7a9d3e7 to your computer and use it in GitHub Desktop.
import requests | |
import json | |
import calendar | |
from datetime import datetime, timedelta | |
#token from https://api.slack.com/web | |
_token = "YOUR TOKEN HERE" | |
_domain = "YOUR SUB DOMAIN HERE" | |
if __name__ == '__main__': | |
while 1: | |
files_list_url = 'https://slack.com/api/files.list' | |
date = str(calendar.timegm((datetime.now() + timedelta(-30)) | |
.utctimetuple())) | |
data = {"token": _token, "ts_to": date} | |
response = requests.post(files_list_url, data = data) | |
if len(response.json()["files"]) == 0: | |
break | |
for f in response.json()["files"]: | |
print "Deleting file " + f["name"] + "..." | |
timestamp = str(calendar.timegm(datetime.now().utctimetuple())) | |
delete_url = "https://" + _domain + ".slack.com/api/files.delete?t=" + timestamp | |
requests.post(delete_url, data = { | |
"token": _token, | |
"file": f["id"], | |
"set_active": "true", | |
"_attempts": "1"}) | |
print "DONE!" |
Im getting an error running this
File "slack2.py", line 20
print "Deleting file " + f["name"] + "..."
^
SyntaxError: Missing parentheses in call to 'print'
@theapplepastor it looks like you're using python 3, so print
is a function. As such, you'll need to use print(stuff)
rather than print stuff
.
Thanks for this! I just created a similar script using argparse rather than hard coding _token
hope this is helpful to people https://gitlab.com/tomleo/SlackFileCleanup/
Python: How to delete multiple files from server at once using OVH cloud API ? can you help me please
I want to delete files from the server using the Pycurl or Python request method. I have a list of file names and I want to delete all files from OVH server by comparing name with the List items. I am using OVH cloud API.
I'd seen this code posted elsewhere, not in the gist, so I started reworking it without realizing I could do a pull request ... then searched for a line in the code again and found this gist.
Anyway, a partial reworking with utf-8 handling, improved messaging and multiple accounts is posted here:
https://github.com/PalmBeachPost/SlackPruner
Thanks! I hope this is OK. If you'd rather fold some of this back into the gist or something, please let me know.