Spaces:
Sleeping
Sleeping
Update src/reddit_client.py
Browse files- src/reddit_client.py +10 -4
src/reddit_client.py
CHANGED
|
@@ -1,18 +1,24 @@
|
|
| 1 |
-
import os
|
| 2 |
import praw
|
| 3 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
reddit = praw.Reddit(
|
| 5 |
-
client_id=
|
| 6 |
-
client_secret=
|
| 7 |
-
user_agent=
|
| 8 |
)
|
|
|
|
| 9 |
reddit.read_only = True # Avoids login requirements
|
| 10 |
|
| 11 |
def search_reddit(brand, limit=10):
|
| 12 |
posts = []
|
| 13 |
try:
|
|
|
|
| 14 |
for post in reddit.subreddit("all").search(brand, sort="new", limit=limit):
|
| 15 |
posts.append(post)
|
| 16 |
except Exception as e:
|
| 17 |
print("Reddit search failed:", e)
|
|
|
|
| 18 |
return posts
|
|
|
|
|
|
|
| 1 |
import praw
|
| 2 |
|
| 3 |
+
REDDIT_CLIENT_ID = "Ci6GbL5EK3dIaQ2tGH9yjA"
|
| 4 |
+
REDDIT_CLIENT_SECRET = "ddWkwRm_0O9J1bFZ-SOKNmTJbY75zA"
|
| 5 |
+
REDDIT_USER_AGENT = "brand_monitor_app by u/OutrageousResist6035"
|
| 6 |
+
|
| 7 |
reddit = praw.Reddit(
|
| 8 |
+
client_id=REDDIT_CLIENT_ID,
|
| 9 |
+
client_secret=REDDIT_CLIENT_SECRET,
|
| 10 |
+
user_agent=REDDIT_USER_AGENT
|
| 11 |
)
|
| 12 |
+
|
| 13 |
reddit.read_only = True # Avoids login requirements
|
| 14 |
|
| 15 |
def search_reddit(brand, limit=10):
|
| 16 |
posts = []
|
| 17 |
try:
|
| 18 |
+
# Search posts in 'all' subreddit, sorted by newest
|
| 19 |
for post in reddit.subreddit("all").search(brand, sort="new", limit=limit):
|
| 20 |
posts.append(post)
|
| 21 |
except Exception as e:
|
| 22 |
print("Reddit search failed:", e)
|
| 23 |
+
|
| 24 |
return posts
|