A command-line tool to display top posts from any subreddit in your terminal. This tool fetches and displays Reddit's top posts with details including title, author, score, comment count, and direct link to the post.
- Python 3.6 or higher
requestslibrary
- Install the required dependency:
pip install requests- Make the script executable (optional):
chmod +x reddit_viewer.pyView top 10 posts from a subreddit:
python reddit_viewer.py pythonSpecify the number of posts to display (1-100):
python reddit_viewer.py python --limit 20or
python reddit_viewer.py python -l 20Display help information:
python reddit_viewer.py --help# View top 10 posts from r/programming
python reddit_viewer.py programming
# View top 25 posts from r/learnpython
python reddit_viewer.py learnpython --limit 25
# View top 5 posts from r/news
python reddit_viewer.py news -l 5- ✨ Simple CLI interface with argument parsing
- 🎯 Fetches top posts from any public subreddit
- 📊 Displays key post information (title, author, score, comments)
- 🔗 Direct links to view posts on Reddit
- ⚡ No Reddit API authentication required
- 📏 Approximately 100 lines of Python code
The tool displays posts in the following format:
================================================================================
Top 10 Posts from r/python
================================================================================
1. Example Post Title
Author: u/username | Score: 1234 | Comments: 56
URL: https://reddit.com/r/python/comments/...
2. Another Example Post
Author: u/another_user | Score: 890 | Comments: 23
URL: https://reddit.com/r/python/comments/...
...
- This tool uses Reddit's public JSON API (no authentication required)
- The tool displays top posts from the past day by default
- Maximum limit is 100 posts per Reddit's API restrictions
- Long post titles are truncated to 70 characters for better readability
This project is part of the 100 Lines of Python Code repository.
Created for issue #989 - Reddit Top Post Viewer
Follows the repository's license.