Spaces:
Paused
Paused
Update services/aggregator.py
Browse files- services/aggregator.py +13 -6
services/aggregator.py
CHANGED
|
@@ -2,18 +2,25 @@ from services.youtube import search_videos, get_comments
|
|
| 2 |
from services.reddit import get_reddit_comments
|
| 3 |
from services.preprocessing import clean_text
|
| 4 |
|
| 5 |
-
def collect_data(keyword):
|
| 6 |
all_comments = []
|
| 7 |
|
| 8 |
# YouTube
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
# Reddit
|
| 14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
# Clean
|
| 17 |
cleaned = [clean_text(c) for c in all_comments if len(c) > 5]
|
| 18 |
|
| 19 |
return cleaned
|
|
|
|
| 2 |
from services.reddit import get_reddit_comments
|
| 3 |
from services.preprocessing import clean_text
|
| 4 |
|
| 5 |
+
def collect_data(keyword, source="all"):
|
| 6 |
all_comments = []
|
| 7 |
|
| 8 |
# YouTube
|
| 9 |
+
if source in ["youtube", "all"]:
|
| 10 |
+
try:
|
| 11 |
+
video_ids = search_videos(keyword)
|
| 12 |
+
for vid in video_ids:
|
| 13 |
+
all_comments.extend(get_comments(vid))
|
| 14 |
+
except Exception as e:
|
| 15 |
+
print("YouTube error:", e)
|
| 16 |
|
| 17 |
# Reddit
|
| 18 |
+
if source in ["reddit", "all"]:
|
| 19 |
+
try:
|
| 20 |
+
all_comments.extend(get_reddit_comments(keyword))
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print("Reddit error:", e)
|
| 23 |
|
|
|
|
| 24 |
cleaned = [clean_text(c) for c in all_comments if len(c) > 5]
|
| 25 |
|
| 26 |
return cleaned
|