Last active
July 23, 2016 17:30
-
-
Save renanccastro/5157d6752b839a6ce8e7f2ab83b47b70 to your computer and use it in GitHub Desktop.
deletando files próprios
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
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 |
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
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