Skip to content

M1keEm/RedditBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Reddit Bot for Python Enthusiasts

License Python PRAW

A simple Reddit bot built using Python and the PRAW (Python Reddit API Wrapper) library. This bot monitors the pythonforengineers subreddit for posts containing the phrase "i love python" and replies with a predefined message. It also keeps track of posts it has already replied to, ensuring no duplicate responses.


Table of Contents


Features

  • Automated Replies: Replies to posts containing the phrase "i love python" with a predefined message.
  • Duplicate Prevention: Tracks replied posts to avoid duplicate responses.
  • Subreddit Monitoring: Monitors the pythonforengineers subreddit for new posts.
  • Logging: Prints detailed information about the posts it replies to.

Installation

To run the Reddit bot, follow these steps:

  1. Install Python:

  2. Install PRAW:

    • Install the PRAW library using pip:
      pip install praw
  3. Clone the repository:

    git clone https://github.com/M1keEm/RedditBot.git
    
  4. Navigate to the project directory:

    cd RedditBot
    
  5. Set up Reddit API credentials:


Usage

  1. Run the bot:

    python main.py
    
  2. Monitor output:

    • The bot will print details about the posts it replies to, including the title, URL, and author information.
  3. Check replied posts:

    • The bot maintains a list of replied posts in posts_replied_to.txt.

How it works

Key Components

  1. PRAW Initialization:

    • The bot uses the PRAW library to interact with the Reddit API.

    • It logs in using the credentials provided in praw.ini.

  2. Post Monitoring:

    • The bot fetches the top 5 hot posts from the pythonforengineers subreddit.
  3. Keyword Matching:

    • It checks if the post title contains the phrase "i love python" (case-insensitive).
  4. Reply and Logging:

    • If a match is found, the bot replies with "Manual bot test" and logs the post details.

    • The post ID is saved to posts_replied_to.txt to prevent duplicate replies.


Configuration

praw.ini File

Create a praw.ini file with the following content:

[bot1]
client_id=YOUR_CLIENT_ID
client_secret=YOUR_CLIENT_SECRET
username=YOUR_REDDIT_USERNAME
password=YOUR_REDDIT_PASSWORD
user_agent=YOUR_USER_AGENT

Replace the placeholders with your Reddit app credentials.

Customizing the Bot

  • Change the reply message: Modify the submission.reply("Manual bot test") line in main.py.

  • Change the subreddit: Update subreddit = reddit.subreddit('pythonforengineers') to your desired subreddit.

  • Change the keyword: Update the re.search("i love python", submission.title, re.IGNORECASE) line to match a different keyword.


Contributing

Contributions are welcome! If you'd like to contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch (git checkout -b feature/YourFeatureName).
  3. Commit your changes (git commit -m 'Add some feature').
  4. Push to the branch (git push origin feature/YourFeatureName).
  5. Open a pull request.

Please ensure your code follows the existing style and includes appropriate documentation.


License

This project is licensed under the MIT License. See the LICENSE file for details.


Contact

If you have any questions or suggestions, feel free to reach out:

About

A simple read and reply bot in python using praw.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages