Spaces:
Sleeping
Sleeping
Update services/aggregator.py
Browse files- services/aggregator.py +11 -5
services/aggregator.py
CHANGED
|
@@ -5,7 +5,7 @@ from services.preprocessing import clean_text
|
|
| 5 |
def collect_data(keyword, source="all"):
|
| 6 |
all_comments = []
|
| 7 |
|
| 8 |
-
#
|
| 9 |
if source in ["youtube", "all"]:
|
| 10 |
try:
|
| 11 |
video_ids = search_videos(keyword)
|
|
@@ -14,13 +14,19 @@ def collect_data(keyword, source="all"):
|
|
| 14 |
except Exception as e:
|
| 15 |
print("YouTube error:", e)
|
| 16 |
|
| 17 |
-
#
|
| 18 |
if source in ["reddit", "all"]:
|
| 19 |
try:
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
except Exception as e:
|
| 22 |
-
print("Reddit error:", e)
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
return cleaned
|
|
|
|
| 5 |
def collect_data(keyword, source="all"):
|
| 6 |
all_comments = []
|
| 7 |
|
| 8 |
+
# ✅ YOUTUBE (WAJIB)
|
| 9 |
if source in ["youtube", "all"]:
|
| 10 |
try:
|
| 11 |
video_ids = search_videos(keyword)
|
|
|
|
| 14 |
except Exception as e:
|
| 15 |
print("YouTube error:", e)
|
| 16 |
|
| 17 |
+
# ✅ REDDIT (OPSIONAL - JANGAN BIARKAN CRASH)
|
| 18 |
if source in ["reddit", "all"]:
|
| 19 |
try:
|
| 20 |
+
reddit_comments = get_reddit_comments(keyword)
|
| 21 |
+
if reddit_comments:
|
| 22 |
+
all_comments.extend(reddit_comments)
|
| 23 |
except Exception as e:
|
| 24 |
+
print("Reddit error (skip):", e)
|
| 25 |
|
| 26 |
+
# 🔥 FALLBACK (BIAR GA KOSONG)
|
| 27 |
+
if len(all_comments) == 0:
|
| 28 |
+
all_comments = ["data tidak ditemukan"]
|
| 29 |
+
|
| 30 |
+
cleaned = [clean_text(c) for c in all_comments if len(c) > 3]
|
| 31 |
|
| 32 |
return cleaned
|