Created
September 2, 2020 05:40
-
-
Save diatche/ca905ed7d22c753a8d474e1ebf05fc29 to your computer and use it in GitHub Desktop.
Deletes old bot Slack messages using slack_cleaner2
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
# Deletes old bot Slack messages using slack_cleaner2 | |
# https://github.com/sgratzl/slack-cleaner | |
# Usage: | |
# 1. Install slack_cleaner2 and Arrow | |
# 2. Run with token as CLI arg. E.g. `python slack_cleaner.py <token xoxp-...>` | |
import arrow | |
import time | |
import sys | |
from slack_cleaner2 import * | |
date_max = arrow.now().shift(days=-7).floor('day') | |
date_format = 'DD/MM/YYYY' | |
token = str(sys.argv[1]) | |
s = SlackCleaner(token) | |
# list of all kind of channels | |
convs = s.conversations | |
# delete all messages in -bot channels | |
channels = list(filter(match('.*-bot'), convs)) | |
print(f'Deleting bot messages before {date_max.format(date_format)} from channels: {channels}') | |
messages = s.msgs( | |
channels=channels, | |
before=date_max.timestamp | |
) | |
for msg in messages: | |
if msg.bot: | |
# date = arrow.get(msg.ts).to('local') | |
# print(f'Deleting {msg.user or "bot"} message dated {date}') | |
msg.delete() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment