Skip to content

Commit

Permalink
Merge pull request #50 from sgratzl/sgratzl/public2private
Browse files Browse the repository at this point in the history
fix not finding groups by using conversation api
  • Loading branch information
sgratzl authored May 13, 2019
2 parents d89e829 + e4f1be0 commit 5d7fcca
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 23 deletions.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
slacker
slacker>=0.13.0
colorama
2 changes: 1 addition & 1 deletion slack_cleaner/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = 'Lin, Ke-fei, Samuel Gratzl'
__authoremail__ = '[email protected], [email protected]'
__version__ = '0.5.1'
__version__ = '0.6.0'
31 changes: 10 additions & 21 deletions slack_cleaner/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,9 @@ def clean_channel(channel_id, channel_type, time_range, user_id=None, bot=False)
oldest = time_range.start_ts
latest = time_range.end_ts

_api_end_point = None
# Set to the right API end point
if channel_type == 'channel':
_api_end_point = slack.channels.history
elif channel_type == 'direct':
_api_end_point = slack.im.history
elif channel_type == 'group':
_api_end_point = slack.groups.history
elif channel_type == 'mpdirect':
_api_end_point = slack.mpim.history

has_more = True
while has_more:
res = _api_end_point(channel_id, latest, oldest).body
res = slack.conversations.history(channel_id, latest=latest, oldest=oldest).body
if not res['ok']:
logger.error('Error occurred on Slack\'s API:')
pp.pprint(res)
Expand Down Expand Up @@ -314,10 +303,10 @@ def get_direct_ids_by_pattern(pattern, equality_match):


def get_group_ids_by_pattern(pattern, equality_match):
res = slack.groups.list().body
if not res['ok'] or not res['groups']:
res = slack.conversations.list(types='private_channel').body
if not res['ok'] or not res['channels']:
return []
return match_by_key(pattern, res['groups'], lambda c: c['name'], equality_match)
return match_by_key(pattern, res['channels'], lambda c: c['name'], equality_match)


def get_mpdirect_ids_by_pattern(pattern):
Expand Down Expand Up @@ -433,28 +422,28 @@ def print_dict(name, d):
logger.info(m)

res = slack.users.list().body
if res['ok'] and res['members']:
if res['ok'] and res.get('members'):
users = {c['id']: u'{n} = {r}'.format(n=c['name'], r=c['profile']['real_name']) for c in res['members']}
else:
users = {}
print_dict('users', users)

res = slack.channels.list().body
if res['ok'] and res['channels']:
if res['ok'] and res.get('channels'):
channels = {c['id']: c['name'] for c in res['channels']}
else:
channels = {}
print_dict('public channels', channels)

res = slack.groups.list().body
if res['ok'] and res['groups']:
groups = {c['id']: c['name'] for c in res['groups']}
res = slack.conversations.list(types='private_channel').body
if res['ok'] and res.get('channels'):
groups = {c['id']: c['name'] for c in res['channels']}
else:
groups = {}
print_dict('private channels', groups)

res = slack.im.list().body
if res['ok'] and res['ims']:
if res['ok'] and res.get('ims'):
ims = { c['id']: user_dict[c['user']] for c in res['ims']}
else:
ims = {}
Expand Down

0 comments on commit 5d7fcca

Please sign in to comment.