A Python script that fetches and displays the top posts from any subreddit using Reddit's public JSON API. No authentication required!
- Fetch top posts from any public subreddit
- Customizable number of posts (1-100)
- Multiple time filter options (hour, day, week, month, year, all)
- Displays post title, author, score, timestamp, and link
- Clean, formatted output in the terminal
- User-friendly command-line interface
pip install requestspython reddit_top_posts_viewer.pyYou'll be prompted to enter:
- Subreddit name
- Number of posts to view
- Time filter period
python reddit_top_posts_viewer.py pythonPass the subreddit name as an argument, then follow the prompts for additional options.
================================================================================
Top 5 Posts
================================================================================
1. Getting Started with Python in 2025
Author: u/pythondev
Score: 2,543 | Posted: 2025-10-18 10:30:00
Link: https://www.reddit.com/r/python/comments/...
--------------------------------------------------------------------------------
2. Best Python Libraries for Data Science
Author: u/datascientist
Score: 1,892 | Posted: 2025-10-18 08:15:00
Link: https://www.reddit.com/r/python/comments/...
--------------------------------------------------------------------------------
hour- Top posts from the last hourday- Top posts from the last 24 hours (default)week- Top posts from the last weekmonth- Top posts from the last monthyear- Top posts from the last yearall- Top posts of all time
- Object-oriented design with RedditTopPostsViewer class
- Error handling for network requests
- Input validation for user inputs
- Clean separation of concerns (fetch, display, main)
- Under 100 lines of Python code
- Uses Reddit's public JSON API (no API key required)
- Rate limiting applies - be respectful with requests
- Only works with public subreddits
- Requires internet connection
This solution addresses Issue #1096: Reddit Top Posts Viewer
Contributed to 100LinesOfPythonCode repository