-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathoutput_slack.py
More file actions
137 lines (108 loc) Β· 4.39 KB
/
output_slack.py
File metadata and controls
137 lines (108 loc) Β· 4.39 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python3
"""
Slack Output Module
Posts signal alerts to Slack #taolor channel
Uses Clawdbot's message tool for delivery
"""
import json
import subprocess
from datetime import datetime
from pathlib import Path
SLACK_CHANNEL = "C0AB131GF9V" # #taolor
def format_signal_message(signals: list) -> str:
"""Format signals into a Slack message"""
if not signals:
return ""
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
# Group by severity
critical = [s for s in signals if s.get("severity") == "critical"]
high = [s for s in signals if s.get("severity") == "high"]
medium = [s for s in signals if s.get("severity") == "medium"]
lines = [
f"π *TAOLOR SIGNAL ALERT* β {timestamp}",
""
]
if critical:
lines.append("π¨ *CRITICAL β Multi-Signal Alignment*")
for s in critical:
lines.append(f"β’ *{s.get('subnet_name', 'Unknown')}*: {s.get('detail', '')}")
lines.append("")
if high:
lines.append("π₯ *HIGH PRIORITY*")
for s in high:
signal_type = s.get('type', '').replace('_', ' ').title()
lines.append(f"β’ *{s.get('subnet_name', 'Unknown')}* ({signal_type}): {s.get('detail', '')}")
lines.append("")
if medium:
lines.append("π *SIGNALS*")
for s in medium:
signal_type = s.get('type', '').replace('_', ' ').title()
lines.append(f"β’ {s.get('subnet_name', 'Unknown')} ({signal_type}): {s.get('detail', '')}")
lines.append("")
lines.append("_Signals don't wait. Neither should you._")
return "\n".join(lines)
def format_daily_summary(data_path: Path) -> str:
"""Create a daily summary from collected data"""
lines = [
f"π *TAOLOR DAILY SUMMARY* β {datetime.now().strftime('%Y-%m-%d')}",
""
]
# GitHub activity
github_file = data_path / "github_latest.json"
if github_file.exists():
with open(github_file) as f:
github = json.load(f)
total_commits = github.get("aggregate", {}).get("total_commits_7d", 0)
most_active = github.get("aggregate", {}).get("most_active", [])[:3]
lines.append(f"*π GitHub Activity (7d):* {total_commits} commits")
for repo in most_active:
lines.append(f" β’ {repo['repo'].split('/')[-1]}: {repo['commits']} commits")
lines.append("")
# Subnet data
subnet_file = data_path / "subnets_latest.json"
if subnet_file.exists():
with open(subnet_file) as f:
subnets = json.load(f)
subnet_count = len(subnets.get("subnets", {}))
lines.append(f"*π Subnets Tracked:* {subnet_count}")
lines.append("")
# KOL activity
kol_file = data_path / "kol_tweets_latest.json"
if kol_file.exists():
with open(kol_file) as f:
kols = json.load(f)
tweets_24h = kols.get("aggregate", {}).get("total_tweets_24h", 0)
top_mentions = list(kols.get("aggregate", {}).get("subnet_mentions", {}).items())[:5]
if tweets_24h > 0:
lines.append(f"*π¦ KOL Activity (24h):* {tweets_24h} tweets")
if top_mentions:
mentions_str = ", ".join([f"{k}: {v}" for k, v in top_mentions])
lines.append(f" Top mentions: {mentions_str}")
lines.append("")
lines.append("_Run `./run.sh` for full analysis_")
return "\n".join(lines)
def post_to_slack(message: str, channel: str = SLACK_CHANNEL) -> bool:
"""Post message to Slack using Clawdbot message tool"""
if not message:
return False
# Write message to temp file for Clawdbot to pick up
output_dir = Path(__file__).parent / "output"
output_dir.mkdir(exist_ok=True)
pending_file = output_dir / "pending_slack.json"
with open(pending_file, "w") as f:
json.dump({
"channel": channel,
"message": message,
"timestamp": datetime.now().isoformat()
}, f, indent=2)
print(f"π€ Slack message queued: {len(message)} chars")
return True
def main():
"""Generate and queue daily summary"""
data_path = Path(__file__).parent / "data"
summary = format_daily_summary(data_path)
if summary:
post_to_slack(summary)
print(summary)
if __name__ == "__main__":
main()