noranisa commited on
Commit
1f3b000
·
verified ·
1 Parent(s): 7cb2aba

Update services/aggregator.py

Browse files
Files changed (1) hide show
  1. 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
- all_comments = []
7
 
8
- # YouTube
9
  if source in ["youtube", "all"]:
10
  vids = search_videos(keyword)
11
  for v in vids:
12
- all_comments.extend(get_comments(v))
 
 
13
 
14
- # Reddit
15
  if source in ["reddit", "all"]:
16
- all_comments.extend(get_reddit_comments(keyword))
 
 
17
 
18
- # fallback
19
- if not all_comments:
20
- all_comments = ["data tidak ditemukan"]
21
 
22
  cleaned = [
23
- clean_text(c)
24
- for c in all_comments
25
- if is_valid(c)
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