Browse Tag: chat bot

Create a Reddit Bot that automatically replies to Questions on AskReddit using Python

I recently published an article on creating a basic Reddit Chatbot you would be able to ask it questions and it would search Reddit for the answer and reply with an answer. This is an upgraded version of the previous Reddit bot I created except this one will actually post replies on Reddit and other users will assume it is a real person replying to their questions. I used Reddit s PRAW library that uses the Reddit API and makes it very easy to search for submissions and grabbing comments and posting reply’s on Reddit. You will need to install the PRAW library in Python to use this script.

The way the script works is it monitors /r/AskReddit for new submissions and grabs the title of the new submission. After it grabs the title it will search Reddit using the title and try to see if the question was asked before. If it was asked before it will look at the comments to that question, grab a random comment and reply to the new submission with the grabbed comment. Its actully very ingenious and has a very high confidence rating when replying to submissions.

I use my Raspberry Pi to run my bot since my Raspberry Pi is always on and connected to the internet. Using the Raspberry Pi allows my bot to be running 24/7 which is nice to watch it respond to people all the time.

Objective

To create a Reddit Bot that automatically replies to Questions on the AskReddit subreddit using Python

Material

You will need the following:

Instructions

I will go over the functions and steps I used to create my Reddit bot below and try to explain what I am going to get the Bot the work. At the bottom I will combine everything together. You should be able to simply copy and paste the final code into Python, add your bot’s API credentials and it will start replying to comments.

Continue Reading

How to Create a Simple Python Chatbot on the Raspberry Pi

I have recently been working on a new project that required scraping data from other websites and have been slowly learning python. I usually work with PHP but I knew python will work faster and better. I also have always wanted to create a simple chatbot that I can input text into and it would reply with something meaningful. Creating a chatbot with a huge database of words and actually understanding what is being said is not an easy task and is something that is way over my head. I was browsing Reddit and found out that you can get results in JSON format is you append ‘.json‘ to the end of the URL. This got me thinking, what if I search Reddit with a question or comment and pick a random search result and reply with one of the top comments. This would fill my urge in creating a chatbot and it would also be a good starting point if I ever wanted to go deeper into creating a database and store answers for the chatbot to get a personality of its own.

I figured the Raspberry Pi would be an easy starting point since I have a bunch of them laying around and it is already setup with a Python environment. You can easily replicate this in any Python environment but I tested out my chatbot on the Raspberry Pi.

Objective

To create a chatbot in Python on the Raspberry Pi that searches Reddit and replies using a Reddit comment

Material

You will need the following:

Instructions

Create a new file on the Raspberry Pi and call it main.py Continue Reading