Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,30 @@
|
|
1 |
-
import praw
|
2 |
import os
|
|
|
|
|
|
|
|
|
|
|
3 |
|
|
|
|
|
4 |
|
5 |
-
client_id = os.getenv('
|
6 |
-
client_secret = os.getenv('
|
7 |
-
user_agent = os.getenv('
|
8 |
username = os.getenv('REDDIT_USERNAME')
|
9 |
password = os.getenv('REDDIT_PASSWORD')
|
10 |
|
11 |
-
#
|
12 |
-
print("
|
13 |
-
|
14 |
-
client_secret = 'CLIENT_SECRET'
|
15 |
-
user_agent = 'USER_AGENT'
|
16 |
-
username = 'REDDIT_USERNAME'
|
17 |
-
password = 'REDDIT_PASSWORD'
|
18 |
-
|
19 |
-
# Print lengths of client ID and secret to ensure they're set (but don't print actual secrets)
|
20 |
-
print(f"Client ID length: {len(client_id)}")
|
21 |
-
print(f"Client Secret length: {len(client_secret)}")
|
22 |
print(f"User Agent: {user_agent}")
|
23 |
print(f"Username: {username}")
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
try:
|
26 |
reddit = praw.Reddit(
|
@@ -33,11 +37,13 @@ try:
|
|
33 |
print("Reddit instance created successfully.")
|
34 |
except Exception as e:
|
35 |
print(f"Error creating Reddit instance: {e}")
|
|
|
36 |
|
37 |
def monitor_new_posts():
|
38 |
try:
|
39 |
print("Attempting to access subreddit...")
|
40 |
-
|
|
|
41 |
print(f"Successfully accessed subreddit: {subreddit.display_name}")
|
42 |
except Exception as e:
|
43 |
print(f"Error accessing subreddit: {e}")
|
|
|
|
|
1 |
import os
|
2 |
+
import praw
|
3 |
+
from dotenv import load_dotenv # Only if using .env file
|
4 |
+
|
5 |
+
# Load environment variables from .env file (only if using .env file)
|
6 |
+
load_dotenv()
|
7 |
|
8 |
+
# Reddit API credentials retrieved from environment variables
|
9 |
+
print("Initializing Reddit instance...")
|
10 |
|
11 |
+
client_id = os.getenv('REDDIT_CLIENT_ID')
|
12 |
+
client_secret = os.getenv('REDDIT_CLIENT_SECRET')
|
13 |
+
user_agent = os.getenv('REDDIT_USER_AGENT')
|
14 |
username = os.getenv('REDDIT_USERNAME')
|
15 |
password = os.getenv('REDDIT_PASSWORD')
|
16 |
|
17 |
+
# Print out the values to ensure they are loaded (mask sensitive info)
|
18 |
+
print(f"Client ID: {client_id}")
|
19 |
+
print(f"Client Secret is set: {'Yes' if client_secret else 'No'}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
print(f"User Agent: {user_agent}")
|
21 |
print(f"Username: {username}")
|
22 |
+
print(f"Password is set: {'Yes' if password else 'No'}")
|
23 |
+
|
24 |
+
# Check if all credentials are retrieved successfully
|
25 |
+
if not all([client_id, client_secret, user_agent, username, password]):
|
26 |
+
print("Error: One or more environment variables are missing.")
|
27 |
+
exit(1)
|
28 |
|
29 |
try:
|
30 |
reddit = praw.Reddit(
|
|
|
37 |
print("Reddit instance created successfully.")
|
38 |
except Exception as e:
|
39 |
print(f"Error creating Reddit instance: {e}")
|
40 |
+
exit(1) # Exit if Reddit instance cannot be created
|
41 |
|
42 |
def monitor_new_posts():
|
43 |
try:
|
44 |
print("Attempting to access subreddit...")
|
45 |
+
subreddit_name = 'your_subreddit_name' # Replace with your subreddit
|
46 |
+
subreddit = reddit.subreddit(subreddit_name)
|
47 |
print(f"Successfully accessed subreddit: {subreddit.display_name}")
|
48 |
except Exception as e:
|
49 |
print(f"Error accessing subreddit: {e}")
|