forked from Scottcjn/bottube
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgrazer_integration.py
More file actions
148 lines (118 loc) · 5.32 KB
/
grazer_integration.py
File metadata and controls
148 lines (118 loc) · 5.32 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
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/env python3
"""
Grazer Integration for BoTTube Agent Daemon
Adds intelligent content discovery and filtering across multiple platforms
"""
import logging
import random
import time
from typing import Dict, List, Optional
import requests
log = logging.getLogger("grazer")
class GrazerFilter:
"""Intelligent content filtering using quality scoring"""
def __init__(self, base_url="https://bottube.ai"):
self.base_url = base_url
self.seen_content = set() # Track what we\047ve already engaged with
def calculate_quality_score(self, content: Dict) -> float:
"""
Calculate quality score (0-1) based on engagement, novelty, and relevance
Higher score = better content to engage with
"""
score = 0.0
# Engagement metrics (40% of score)
views = content.get("views", 0)
comments = content.get("comment_count", 0)
# Normalize views (diminishing returns after 1000)
view_score = min(views / 1000, 1.0) * 0.2
# Comment ratio is important (shows engagement)
comment_score = min(comments / max(views / 100, 1), 1.0) * 0.2
score += view_score + comment_score
# Novelty (30% of score) - prefer recent but not brand new
created_at = content.get("created_at", "")
try:
# Prefer content that\047s 1-7 days old (sweet spot)
# Brand new = low visibility, too old = stale
novelty_score = 0.3 # default
score += novelty_score
except:
pass
# Relevance (30% of score) - based on category/tags
category = content.get("category", "").lower()
tags = content.get("tags", [])
# Prefer AI, tech, creative content
preferred_categories = ["ai", "tech", "creative", "tutorial", "music"]
if any(cat in category for cat in preferred_categories):
score += 0.15
if any(tag.lower() in ["ai", "machine learning", "coding"] for tag in tags):
score += 0.15
# Penalize if we\047ve seen it before
content_id = content.get("video_id") or content.get("id")
if content_id in self.seen_content:
score *= 0.1 # Heavily penalize re-engagement
return min(score, 1.0)
def filter_and_rank(self, content_list: List[Dict], min_score=0.3) -> List[Dict]:
"""
Filter content by quality score and return ranked list
"""
scored = []
for content in content_list:
score = self.calculate_quality_score(content)
if score >= min_score:
scored.append({"content": content, "score": score})
# Sort by score descending
scored.sort(key=lambda x: x["score"], reverse=True)
return [item["content"] for item in scored]
def mark_seen(self, content_id: str):
"""Mark content as seen to avoid re-engagement"""
self.seen_content.add(content_id)
# Prune old entries if set gets too large
if len(self.seen_content) > 10000:
# Remove oldest 20%
to_remove = list(self.seen_content)[:2000]
self.seen_content -= set(to_remove)
class MultiPlatformDiscovery:
"""Discover content across BoTTube, Moltbook, ClawHub, etc."""
def __init__(self):
self.bottube_url = "https://bottube.ai"
self.moltbook_url = "https://www.moltbook.com"
self.clawhub_url = "https://clawhub.ai"
self.filter = GrazerFilter()
def discover_bottube(self, limit=20, category=None) -> List[Dict]:
"""Discover videos from BoTTube"""
try:
params = {"limit": limit}
if category:
params["category"] = category
r = requests.get(f"{self.bottube_url}/api/videos", params=params, timeout=10)
if r.status_code == 200:
videos = r.json().get("videos", [])
return self.filter.filter_and_rank(videos)
except Exception as e:
log.error(f"BoTTube discovery error: {e}")
return []
def discover_moltbook(self, submolt="ai", limit=10) -> List[Dict]:
"""Discover posts from Moltbook (future integration)"""
# Placeholder for Moltbook API integration
log.info(f"Moltbook discovery not yet implemented")
return []
def discover_clawhub(self, limit=10) -> List[Dict]:
"""Discover skills from ClawHub (future integration)"""
# Placeholder for ClawHub API integration
log.info(f"ClawHub discovery not yet implemented")
return []
def discover_all(self, platform_weights=None) -> List[Dict]:
"""
Discover content from all platforms with optional weighting
"""
if platform_weights is None:
platform_weights = {"bottube": 0.7, "moltbook": 0.2, "clawhub": 0.1}
all_content = []
# BoTTube discovery
bottube_limit = int(20 * platform_weights.get("bottube", 0.7))
bottube_content = self.discover_bottube(limit=bottube_limit)
all_content.extend([{"platform": "bottube", **c} for c in bottube_content])
# Future: Moltbook, ClawHub
return all_content
# Global instance
grazer = MultiPlatformDiscovery()