test_minimal.pyā¢1.8 kB
#!/usr/bin/env python3
"""
Minimal Reddit API test.
"""
import os
import praw
from dotenv import load_dotenv
def main():
    load_dotenv()
    
    print("š§ Minimal Reddit Test")
    
    reddit = praw.Reddit(
        client_id=os.getenv("REDDIT_CLIENT_ID"),
        client_secret=os.getenv("REDDIT_CLIENT_SECRET"),
        user_agent=os.getenv("REDDIT_USER_AGENT"),
    )
    
    print("ā
 Reddit instance created")
    
    # Try different subreddits
    test_subreddits = ["popular", "all", "AskReddit", "funny"]
    
    for sub_name in test_subreddits:
        try:
            print(f"\nš Testing r/{sub_name}...")
            subreddit = reddit.subreddit(sub_name)
            
            # Just try to access the display name
            name = subreddit.display_name
            print(f"   ā
 Name: {name}")
            
            # Try to get subscriber count (this sometimes fails with 401)
            try:
                subs = subreddit.subscribers
                print(f"   ā
 Subscribers: {subs:,}")
            except Exception as e:
                print(f"   ā ļø  Subscribers failed: {e}")
            
            # Try to get a few hot posts
            try:
                hot_posts = list(subreddit.hot(limit=2))
                print(f"   ā
 Hot posts: {len(hot_posts)} found")
                for post in hot_posts:
                    print(f"      - {post.title[:40]}...")
                break  # If we get here, it's working!
                
            except Exception as e:
                print(f"   ā ļø  Hot posts failed: {e}")
                
        except Exception as e:
            print(f"   ā Failed: {e}")
    
    print(f"\nšÆ If any test succeeded above, your credentials are working!")
if __name__ == "__main__":
    main()