-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplay.py
More file actions
93 lines (72 loc) · 2.47 KB
/
Copy pathplay.py
File metadata and controls
93 lines (72 loc) · 2.47 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import os
from datetime import datetime, timedelta
from dotenv import load_dotenv
from slack_agent import SlackClient
load_dotenv()
client = SlackClient(
token=os.environ["SLACK_TOKEN"],
cookie=os.environ["SLACK_COOKIE"],
)
# Find DM with Mihir
print("Finding DM with Mihir...")
convos = client.get_all_conversations()
mihir_dm_id = None
for im_id in convos["ims"]:
info = client._request("conversations.info", {"channel": im_id})
user_id = info.get("channel", {}).get("user")
if user_id:
user = client.get_user_info(user_id)
if "mihir" in user.name.lower() or "mihir" in user.real_name.lower():
mihir_dm_id = im_id
print(f"Found DM with {user.real_name} ({user.name}): {im_id}")
break
if not mihir_dm_id:
print("Could not find DM with Mihir")
exit(1)
# Get messages from yesterday
yesterday = datetime.now() - timedelta(days=1)
yesterday_start = yesterday.replace(hour=0, minute=0, second=0, microsecond=0)
yesterday_end = yesterday.replace(hour=23, minute=59, second=59, microsecond=999999)
oldest_ts = str(yesterday_start.timestamp())
latest_ts = str(yesterday_end.timestamp())
print(f"\nFetching messages from {yesterday_start.date()}...")
# Fetch all messages from yesterday (paginate if needed)
all_messages = []
cursor = None
while True:
params = {
"channel": mihir_dm_id,
"oldest": oldest_ts,
"latest": latest_ts,
"limit": 200,
}
if cursor:
params["cursor"] = cursor
data = client._request("conversations.history", params)
messages = data.get("messages", [])
all_messages.extend(messages)
cursor = data.get("response_metadata", {}).get("next_cursor")
if not cursor:
break
print(f"Found {len(all_messages)} messages from yesterday\n")
# Get user info for display
user_cache = {}
def get_user_name(user_id):
if not user_id:
return "Unknown"
if user_id not in user_cache:
user = client.get_user_info(user_id)
user_cache[user_id] = user.real_name or user.name
return user_cache[user_id]
# Print messages in chronological order
print("=" * 60)
print(f"MESSAGES FROM {yesterday_start.date()}")
print("=" * 60)
for msg in reversed(all_messages):
ts = float(msg["ts"])
time_str = datetime.fromtimestamp(ts).strftime("%H:%M")
sender = get_user_name(msg.get("user"))
text = msg.get("text", "")
print(f"[{time_str}] {sender}: {text}")
print("=" * 60)
print(f"Total: {len(all_messages)} messages")