Skip to content

Instantly share code, notes, and snippets.

@renanccastro
Last active July 23, 2016 17:30
Show Gist options
  • Save renanccastro/5157d6752b839a6ce8e7f2ab83b47b70 to your computer and use it in GitHub Desktop.
Save renanccastro/5157d6752b839a6ce8e7f2ab83b47b70 to your computer and use it in GitHub Desktop.
deletando files próprios
from slacker import Slacker
# primeiro, instale com: pip install slacker
# deleta todos os arquivos
token = 'gere seu token em: https://api.slack.com/docs/oauth-test-tokens'
name = 'renan.castro'
slack = Slacker(token)
# Get users list
response = slack.users.list()
users = response.body['members']
for u in users:
if u['name'] == name:
userid = u['id']
# delete files
response = slack.files.list(userid)
files = response.body['files']
for f in files:
deleteResponse = slack.files.delete(f['id'])
print deleteResponse.body
from slacker import Slacker
from datetime import timedelta, datetime
# primeiro, instale com: pip install slacker
# deleta somente os enviados ha mais de 30 dias
token = 'gere seu token em: https://api.slack.com/docs/oauth-test-tokens'
name = 'renan.castro'
slack = Slacker(token)
# Get users list
response = slack.users.list()
users = response.body['members']
for u in users:
if u['name'] == name:
userid = u['id']
# delete files
response = slack.files.list(userid)
files = response.body['files']
for f in files:
created = f['created']
dateCreated = datetime.fromtimestamp(created)
# delete if older than 30 days
if dateCreated < datetime.utcnow() + timedelta(days = -30):
deleteResponse = slack.files.delete(f['id'])
print deleteResponse.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment