Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,12 @@ Export 1:1 DMs\
Prompt you to select the conversations to export\
(Any channel/group/user names specified with the other arguments take precedence.)

* `--excludeArchived`\
Exclude any channels that have been archived

* `--excludeNonMember`\
Exclude any public channels for which the user is not a member

### Examples
```
# Export only Public Channels
Expand Down
19 changes: 19 additions & 0 deletions slack_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def promptForPublicChannels(channels):

# fetch and write history for all public channels
def fetchPublicChannels(channels):
print("Fetching", len(channels), "public channels")
if dryRun:
print("Public Channels selected for export:")
for channel in channels:
Expand Down Expand Up @@ -176,6 +177,7 @@ def promptForDirectMessages(dms):
# fetch and write history for all direct message conversations
# also known as IMs in the slack API.
def fetchDirectMessages(dms):
print("Fetching", len(dms), "1:1 DMs")
if dryRun:
print("1:1 DMs selected for export:")
for dm in dms:
Expand All @@ -199,6 +201,7 @@ def promptForGroups(groups):
# fetch and write history for specific private channel
# also known as groups in the slack API.
def fetchGroups(groups):
print("Fetching", len(groups), "Private Channels and Group DMs")
if dryRun:
print("Private Channels and Group DMs selected for export:")
for group in groups:
Expand Down Expand Up @@ -259,6 +262,8 @@ def bootstrapKeyValues():
# Returns the conversations to download based on the command-line arguments
def selectConversations(allConversations, commandLineArg, filter, prompt):
global args
if args.excludeArchived:
allConversations = [ conv for conv in allConversations if not conv["is_archived"] ]
if isinstance(commandLineArg, list) and len(commandLineArg) > 0:
return filter(allConversations, commandLineArg)
elif commandLineArg != None or not anyConversationsSpecified():
Expand Down Expand Up @@ -329,6 +334,18 @@ def finalize():
default=False,
help="Prompt you to select the conversations to export")

parser.add_argument(
'--excludeArchived',
action='store_true',
default=False,
help="Do not export channels that have been archived")

parser.add_argument(
'--excludeNonMember',
action='store_true',
default=False,
help="Only export public channels if the user is a member of the channel")

args = parser.parse_args()

users = []
Expand Down Expand Up @@ -360,6 +377,8 @@ def finalize():
args.publicChannels,
filterConversationsByName,
promptForPublicChannels)
if args.excludeNonMember:
selectedChannels = [ channel for channel in selectedChannels if channel["is_member"] ]

selectedGroups = selectConversations(
groups,
Expand Down