Skip to content

Commit

Permalink
monkey patching slack library to get more than 1000 users :/ os/slack…
Browse files Browse the repository at this point in the history
  • Loading branch information
marianoguerra committed Jun 6, 2020
1 parent 55aec61 commit fa04098
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions slack_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@
from pick import pick
from time import sleep

# START monkey patching stuff
import slacker
import functools
def paginated(list_func):
# See https://api.slack.com/docs/pagination
next_cursor = None
while True:
response = list_func(cursor=next_cursor)
yield response
next_cursor = response.body['response_metadata']['next_cursor']
if not next_cursor:
break

def monkey_patched_list(self, presence=False, cursor=None, limit=None):
return self.get(
'users.list',
params={
'presence': int(presence),
'cursor': cursor,
'limit': limit,
}
)

slacker.Users.list = monkey_patched_list

# END monkey patching stuff

# fetches the complete message history for a channel/group/im
#
# pageableObject could be:
Expand Down Expand Up @@ -164,9 +191,11 @@ def doTestAuth():
# Since Slacker does not Cache.. populate some reused lists
def bootstrapKeyValues():
global users, channels
users = slack.users.list().body['members']
print(u"Found {0} Users".format(len(users)))
sleep(1)
for response in paginated(functools.partial(slack.users.list, limit=500)):
users_page = response.body['members']
print(u"Found {0} Users".format(len(users_page)))
users.extend(users_page)
sleep(1)

channels = slack.channels.list().body['channels']
print(u"Found {0} Public Channels".format(len(channels)))
Expand Down Expand Up @@ -262,10 +291,6 @@ def iso_date_to_slack_timestamp(date_str):
mkdir(outputDirectory)
os.chdir(outputDirectory)

if not dryRun:
dumpUserFile()
dumpChannelFile()

selectedChannels = selectConversations(
channels,
args.publicChannels,
Expand All @@ -285,3 +310,7 @@ def iso_date_to_slack_timestamp(date_str):
from_dtime = to_dtime
to_dtime = to_dtime + one_day

if not dryRun:
dumpUserFile()
dumpChannelFile()

0 comments on commit fa04098

Please sign in to comment.