Searching for Keywords in Reddit using PythonWithin the Reddit API we can mine for messages. In this case we will take a key search word and then find the Top 10 posts on a subreddit [List top posts][Twitter]. |
Theory
Within the Reddit API was can search for keywords or for the Top posts on a subreddit. In the following we search for the last 10 tweets for the key word of "cybersecurity":
import praw import pandas as pd import datetime as dt import sys reddit = praw.Reddit(client_id='xxxxx', \ client_secret='xxxxx', \ user_agent='xxxx', \ username='xxxxx', \ password='xxxx') search_term='cybersecurity' keyword='apple' if (len(sys.argv)>1): search_term=(sys.argv[1]) if (len(sys.argv)>2): keyword=(sys.argv[2]) print "Subreddit: ",search_term print "Keyword: ",keyword print subreddit = reddit.subreddit(search_term) resp = subreddit.search(keyword,limit=10) for submission in resp: print "=ID: ",submission.id print " Title: ",submission.title.encode('ascii', 'ignore') print " Score: ",submission.score print " URL: ",submission.url.encode('ascii', 'ignore') print " Text: ",submission.selftext[:120].encode('ascii', 'ignore')
A sample run is:
Subreddit: cybersecurity Keyword: apple =ID: cfm7uc Title: Israeli spyware used in WhatsApp hack can secretly snoop on your Apple, Facebook and Google data Score: 216 URL: https://www.independent.ie/business/technology/israeli-spyware-used-in-whatsapp-hack-can-secretly-snoop-on-your-apple-facebook-and-google-data-38329481.html Text: =ID: c1nwas Title: Israeli tech company says it can break into all iPhones ever made, some Androids Score: 181 URL: https://www.timesofisrael.com/israeli-tech-company-says-it-can-break-into-all-iphones-ever-made-some-androids/ Text: =ID: bvk9fz Title: Just found out Google has 241 archives of personal data about me of 2GB each; This means half a terabyte 482GB of data potentially shared to third parties, and I have stopped using Google a year ago. Score: 223 URL: https://i.redd.it/wmprwyk4nq131.jpg Text: =ID: bzjxny Title: Is Apple Pay as secure as Apple makes it out to be? Any flaws with it anyone knows about? Score: 81 URL: https://i.redd.it/16mpuf8idt331.jpg Text: =ID: cjvn1b Title: Hey people! Does security folks recommend Android over iOS even Google getting tons of data, regardless this data collection turned off? Does Android still better than iOS? Score: 0 URL: https://www.reddit.com/r/cybersecurity/comments/cjvn1b/hey_people_does_security_folks_recommend_android/ Text: =ID: ci33tp Title: Apple Card could launch in August, report says Score: 1 URL: https://www.cnet.com/news/apple-card-could-launch-in-august-report-says/ Text: =ID: c3edlq Title: What is the most secure (and encrypted) cloud storage program available? Score: 2 URL: https://www.reddit.com/r/cybersecurity/comments/c3edlq/what_is_the_most_secure_and_encrypted_cloud/ Text: I am aware Apple is better than the other big companies, but data is not encrypted as long as it remains on the Cloud. I =ID: bvfye5 Title: Almost got banned from all the best buys after showing staff exploit Score: 0 URL: https://www.reddit.com/r/cybersecurity/comments/bvfye5/almost_got_banned_from_all_the_best_buys_after/ Text: This is an easy vulernability that anyone can do. It's bad because the staff acknowledged it and said they aren't going =ID: c0hs5o Title: Google Confirms that Android Smartphones Have Security Backdoor Flaw Score: 0 URL: https://www.toks.tech/google-confirms-that-android-smartphones-have-security-backdoor-flaw/ Text: =ID: c01gly Title: How secure is google pay compared to apple pay? Score: 1 URL: https://www.reddit.com/r/cybersecurity/comments/c01gly/how_secure_is_google_pay_compared_to_apple_pay/ Text: I'm a noob in regards to cyber security stuff, just wanted to know how secure google pay is in comparison to apple pay,