One of the perks of knowing a programming language is that you can build your own tools and applications. Depending on what you need, it may even be a fast process since you usually do not need to write production grade code and a detailed documentation (although it might still be helpful in the future).
I’ve got used to read news stuff on Reddit, however, it sometimes can be a bit time consuming since it tends to keep you wandering through every and each rabbit hole that pops up. This is fine if you are commuting and have just some spare time to spend on browsing the web but sometimes I just need a quick glance at what’s new and relevant to my interests.
In order to automate this search process, I’ve written a bot that takes as input a list of subreddits, a list of keywords and flags and browses each subreddit looking for the given keywords.
If a keyword is found inside either the body or in the title of a post which has been submitted in one of the selected subreddits, the post title and the links are either printed in the console or saved in a file (in this case the file name must be supplied when starting the search).
The bot is written using praw.
What do I need to use the bot?
In order to use the bot you’ll need to set up an app using your Reddit account and save the client_id, client_secret, username and password in a file named config_data.py which should be stored in the same folder as the reddit_browsing_bot_main.py script.
How does the bot work?
The bot is designed to be a command line application and can be used either in Linux terminal or in the PowerShell if you are the Windows type ;)
This choice of adopting a CLI was undoubtebly a bad choice if I wanted to make other people use the application but in my case I am the end user, and I like command line tools, a lot.
For each subreddit entered, the bot checks if that subreddit exists, if it doesn’t the subreddit is discarded. Then, within each subreddit, the bot searches the first –l posts and returns the posts that contained at least a keyword.
This is an example of use:
reddit_browsing_bot_main.py -s python -k pycon -l 80 -f new -o output.txt –v
In the example above I am searching the first 80 posts in the “new” section of the python
subreddit for posts that mention pycon. The –o flag tells the program to output the results
of the search to the output.txt file. The –v flag makes the program print the output to the
console.
You can search in more subreddits and/or use more keywords, just separate each new
subreddit/keyword with a comma. If you did not supply an output file, the program will
just output the results to the console.
Type:
reddit_browsing_bot_main.py -h
for a help menu. Maybe in the future I’ll add some features but for now this is pretty much it.
Is it ok to use the bot?
As far as I know, the bot is not violating any of the terms written in the Reddit’s API. Also,
the API calls are already limited by the praw module in order to comply with the Reddit’s
API limits. The bot is not downvoting nor upvoting any post, it just reads what is online.
Anyway, should you want to check the code yourself, it is available on its dedicated
GitHub repository or on the project page.
I’ve also copied and pasted a gist below so that you can have a look at the code here:
I simply wanted to write down a quick word to say thanks to you for those wonderful tips and hints you are showing on this site.
ReplyDeletepython training in chennai
Read all the information that i've given in above article. It'll give u the whole idea about it.
ReplyDeleteData Science training in Chennai
Data science training in Bangalore
Data science training in pune
Data science online training
Data Science Interview questions and answers
Data Science Tutorial
Thank you for taking the time and sharing this information with us. It was indeed very helpful and insightful while being straight forward and to the point.
ReplyDeleteData Science Training in Chennai
Data Science course in anna nagar
Data Science course in chennai
Data science course in Bangalore
Data Science course in marathahalli
Data science course in bangalore
Baca juga :
ReplyDeleteSitus Artikel Terbaik di Indonesia
Through this post, I know that your good knowledge in playing with all the pieces was very helpful. I notify that this is the first place where I find issues I've been searching for. You have a clever yet attractive way of writing.data science course in malaysia
ReplyDeleteGreat tips and very easy to understand. This will definitely be very useful for me when I get a chance to start my blog.data science certification malaysia
ReplyDeleteThis article is a great article that I have seen in my python programming career so far.
ReplyDeletewebsite development company in Surat Gujarat
Python Training in Pune
ReplyDeleteThanks for sharing the information about the python and keep updating us.This information is really useful to me.
Python Classes in Pune
Informative blog, Thanks for sharing
ReplyDeletePython Training in Pune
ReplyDeleteThank you for sharing wonderful information with us to get some idea about that content.
Python Online Training Course
Python Developer Course Online Training
I think this is one of the best blog for me because this is really helpful for me. Thanks for sharing this valuable information
ReplyDeleteinternship meaning | internship meaning in tamil | internship work from home | internship certificate format | internship for students | internship letter | Internship completion certificate | internship program | internship certificate online | internship graphic design
Hi, I read your whole blog. This is very nice. Good to know about the career in. Python Training & Certification , anyone interested can Python Training for making their career in this field.
ReplyDeleteThanks for sharing such a useful and wonderful post.
ReplyDeletePython Course in Nagpur
This comment has been removed by the author.
ReplyDeleteamazing write , keep posting and if you are intresting in big data coder and code developer then checkout python classes in pune
ReplyDeleteThanks for the post.
ReplyDeletealso, check Python Classes in Pune