Spaces:
Sleeping
Sleeping
Create services/reddit.py
Browse files- services/reddit.py +18 -0
services/reddit.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import praw
|
| 2 |
+
from config import REDDIT_CLIENT_ID, REDDIT_CLIENT_SECRET, REDDIT_USER_AGENT
|
| 3 |
+
|
| 4 |
+
reddit = praw.Reddit(
|
| 5 |
+
client_id=REDDIT_CLIENT_ID,
|
| 6 |
+
client_secret=REDDIT_CLIENT_SECRET,
|
| 7 |
+
user_agent=REDDIT_USER_AGENT
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
def get_reddit_comments(keyword, limit=50):
|
| 11 |
+
comments = []
|
| 12 |
+
|
| 13 |
+
for submission in reddit.subreddit("all").search(keyword, limit=5):
|
| 14 |
+
submission.comments.replace_more(limit=0)
|
| 15 |
+
for comment in submission.comments.list():
|
| 16 |
+
comments.append(comment.body)
|
| 17 |
+
|
| 18 |
+
return comments[:limit]
|