2
因此,我正在製作一個小型的reddit機器人,它只是在評論中刮掉了一個術語,但我得到了奇怪的結果。我對python非常陌生,所以這段代碼可能有點混亂和成熟。用python分析PRAW中的評論問題
#! /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"
當我運行它,我得到:
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
顯然,這是一個問題,因爲我得到相互矛盾的答案和5個答覆1個請求。
你知道嗎? – fuzz