Last active
December 19, 2023 12:02
-
-
Save thesoftwarejedi/d78af9ee12b7f7a9d3e7 to your computer and use it in GitHub Desktop.
delete old slack files
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
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!" |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@theapplepastor it looks like you're using python 3, so
print
is a function. As such, you'll need to useprint(stuff)
rather thanprint stuff
.