diff --git a/README.md b/README.md index 2e85299..490765f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/slack_export.py b/slack_export.py index 0084ad5..deda6ca 100644 --- a/slack_export.py +++ b/slack_export.py @@ -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: @@ -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: @@ -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: @@ -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(): @@ -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 = [] @@ -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,