Spaces:
Sleeping
Sleeping
Update services/aggregator.py
Browse files- services/aggregator.py +12 -11
services/aggregator.py
CHANGED
|
@@ -3,26 +3,27 @@ from services.reddit import get_reddit_comments
|
|
| 3 |
from services.preprocessing import clean_text, is_valid
|
| 4 |
|
| 5 |
def collect_data(keyword, source="all"):
|
| 6 |
-
|
| 7 |
|
| 8 |
-
# YouTube
|
| 9 |
if source in ["youtube", "all"]:
|
| 10 |
vids = search_videos(keyword)
|
| 11 |
for v in vids:
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
# Reddit
|
| 15 |
if source in ["reddit", "all"]:
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
all_comments = ["data tidak ditemukan"]
|
| 21 |
|
| 22 |
cleaned = [
|
| 23 |
-
clean_text(
|
| 24 |
-
for
|
| 25 |
-
if is_valid(
|
| 26 |
]
|
| 27 |
|
| 28 |
return cleaned
|
|
|
|
| 3 |
from services.preprocessing import clean_text, is_valid
|
| 4 |
|
| 5 |
def collect_data(keyword, source="all"):
|
| 6 |
+
all_data = []
|
| 7 |
|
|
|
|
| 8 |
if source in ["youtube", "all"]:
|
| 9 |
vids = search_videos(keyword)
|
| 10 |
for v in vids:
|
| 11 |
+
comments = get_comments(v)
|
| 12 |
+
for c in comments:
|
| 13 |
+
all_data.append(("youtube", c))
|
| 14 |
|
|
|
|
| 15 |
if source in ["reddit", "all"]:
|
| 16 |
+
comments = get_reddit_comments(keyword)
|
| 17 |
+
for c in comments:
|
| 18 |
+
all_data.append(("reddit", c))
|
| 19 |
|
| 20 |
+
if not all_data:
|
| 21 |
+
all_data = [("unknown", "data tidak ditemukan")]
|
|
|
|
| 22 |
|
| 23 |
cleaned = [
|
| 24 |
+
(src, clean_text(text))
|
| 25 |
+
for src, text in all_data
|
| 26 |
+
if is_valid(text)
|
| 27 |
]
|
| 28 |
|
| 29 |
return cleaned
|