A Snoo Terminal application to browse Reddit posts and comments using the Reddit API.
- View posts from the front page or specific subreddits
- Display comments in a threaded manner
- Pagination for comments
- AI-powered analysis of posts and comments
- Python 3.6 or later
praw
,requests
,beautifulsoup4
,rich
,python-dotenv
,openai
-
Clone the repository:
git clone https://github.com/yourusername/reddit_terminal_reader.git cd reddit_terminal_reader
-
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Create a
.env
file in the root directory with your Reddit API and OpenAI credentials:REDDIT_CLIENT_ID=your_client_id REDDIT_CLIENT_SECRET=your_client_secret REDDIT_USER_AGENT=python.com:your_app:1.0.0 (by u/your_user) OPENAI_API_KEY=your_key
- Go to Reddit's App Preferences.
- Click on "Create App" or "Create Another App" at the bottom of the page.
- Fill in the required fields:
- name: Choose a name for your application.
- App type: Select "script".
- description: (optional) Provide a description for your app.
- about url: (optional) Add a URL for more information about your app.
- redirect uri: Set this to
http://localhost:8000
or any URL you prefer (this won't be used in this script). - permissions: (optional) Set the required permissions.
- Click "Create app".
- Your app will be created, and you will see
client_id
andclient_secret
. Copy these values and add them to your.env
file along with a user agent.
Run the main script to start the Reddit Terminal Reader:
python main.py
/help
- Display the help message/r <subreddit>
- Change to a specific subreddit (e.g.,/r AskReddit
)/sort <method>
- Change the post sorting method. Options:hot
,new
,top
/limit <number>
- Change the number of posts displayed<number>
- View a specific post and its commentsanalyze
- Get AI analysis of the current postn
- View next page of commentsp
- View previous page of commentsb
- Go back to post listo
- Open the current post's URL in your default web browsere <number>
- Expand a specific comment threadc <number>
- Collapse a specific comment threadsort <method>
- Sort comments. Options:best
,new
,controversial
collapse_all
- Collapse all comments to show only root-level commentsmore
- Show more comments (not implemented)q
- Quit the program
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.
- Removed Web Scraping: Web scraping feature was removed due to Reddit blocking such access.
- AI Analysis: Integrated OpenAI's GPT model for detailed analysis of posts and comments.
- Context Management: Implemented strategies to handle context length limitations during AI analysis.
To handle the context length issue when analyzing large Reddit posts and their comments, the following strategies are employed:
- Summarize Long Comments: Summarize individual comments to reduce their length while retaining key information.
- Truncate Excess Comments: Analyze only the top N comments based on upvotes or relevance if there are too many comments.
- Batch Processing: Process the text in batches if it's too long to handle in a single API call, then aggregate the results.
- Selective Inclusion: Include only the most relevant parts of the post and comments, prioritizing highly upvoted comments and those with rich content.
These changes and strategies ensure that the application remains efficient and within the token limits of the AI models used for analysis.