So, I'm making a small reddit bot that just scrapes for a term in comments, but I'm getting weird results. I'm very new to python, so this code might be a bit messy and amature-ish.
#! /usr/bin/python
import praw
import pprint
user_agent = ("simple praw script for searching post terms in comments by /u/shadowfire452")
reddit = praw.Reddit(user_agent = user_agent)
reddit.login()
v_fixed = []
subreddit = reddit.get_subreddit('politics' and 'worldnews')
for submission in subreddit.get_hot(limit = 100):
title = submission.title
if " " in title.lower():
v_fixed.append(title)
print "The following %d posts might not make much sense ..." % (len(v_fixed))
for fixed in v_fixed:
print "\t%s" % (fixed)
flat_comment_generator = praw.helpers.flatten_tree(submission.comments)
for comment in flat_comment_generator:
if "you" in comment.body:
a = []
commentz = comment.body
a.append(commentz)
print comment.body
print ("I found %s comments with 'you' in it out of 100 posts") % (len(a))
else:
print "I found no comments with 'you' in it"
When I run it, I get:
I found 1 comments with ' ' in it out of 100 posts
I found no comments with ' ' in it
I found no comments with ' ' in it
I found no comments with ' ' in it
I found no comments with ' ' in it
Obviously this is an issue, since I'm getting conflicting answers and 5 replies to 1 request.