-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexport_all.py
More file actions
78 lines (63 loc) · 2.53 KB
/
Copy pathexport_all.py
File metadata and controls
78 lines (63 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"""
export_all.py
=============
Exports ALL channels and DMs you are a member of.
Usage:
python export_all.py
"""
import os
import json
from datetime import datetime
from slack_client import (
auth_check, fetch_users, get_all_pages,
export_conversation, write_gpt_file
)
# ─── Config ──────────────────────────────────────────────────────────────────
OUTPUT_DIR = "slack_export/all"
FETCH_FILES = True # download attached files
FETCH_THREADS = True # fetch thread replies
# ─────────────────────────────────────────────────────────────────────────────
def main():
os.makedirs(OUTPUT_DIR, exist_ok=True)
print("Connecting to Slack...")
me, workspace = auth_check()
print(f" Logged in as : {me}")
print(f" Workspace : {workspace}\n")
user_map = fetch_users()
print(f" {len(user_map)} users loaded\n")
print("Fetching all conversations...")
conversations = get_all_pages(
"conversations.list", "channels",
{
"types": "public_channel,private_channel,im,mpim",
"exclude_archived": False,
"limit": 200,
}
)
# Only keep conversations you're actually a member of
conversations = [c for c in conversations if c.get("is_member", True)]
print(f" Found {len(conversations)} conversations\n")
# Save metadata
with open(os.path.join(OUTPUT_DIR, "_conversations.json"), "w") as f:
json.dump(conversations, f, indent=2, ensure_ascii=False)
with open(os.path.join(OUTPUT_DIR, "_users.json"), "w") as f:
json.dump(user_map, f, indent=2, ensure_ascii=False)
gpt_lines = [
"SLACK FULL EXPORT",
f"Workspace : {workspace}",
f"User : {me}",
f"Date : {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}",
f"Total : {len(conversations)} conversations",
]
print("Exporting all conversations...")
for conv in conversations:
lines = export_conversation(
conv, user_map, OUTPUT_DIR,
fetch_files=FETCH_FILES,
fetch_threads=FETCH_THREADS,
)
gpt_lines.extend(lines)
write_gpt_file(OUTPUT_DIR, gpt_lines)
print(f"\nDone! Output saved to: {os.path.abspath(OUTPUT_DIR)}/")
if __name__ == "__main__":
main()