我有一个代码片段,用于检查条件并返回条件(条件)是否为真。
# -*- coding: utf-8 -*-
import re
import settingsTwitter
import tweepy
class StreamListener(tweepy.StreamListener):
httpsCheck = 'https?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+'
httpCheck = 'http?://(?:[-\w.]|(?:%[\da-fA-F]{2}))+'
idSelf = 0
tweet = []
def on_status(self, status):
print "on_status is called"
if status.retweeted:
return
tweetText = status.text.encode('utf8')
created_at = status.created_at
id = status.id
if (re.findall(self.httpCheck, tweetText) or re.findall(self.httpsCheck, tweetText)):
return
if (re.search('[a-zA-Z]', tweetText)):
self.idSelf += 1
self.tweet["text"] = tweetText
self.tweet["time"] = created_at
self.tweet["id"] = id
self.tweet["sequence"] = self.idSelf
def on_error(self, status_code):
if status_code == 420:
return False
auth = tweepy.OAuthHandler(settingsTwitter.TWITTER_APP_KEY, settingsTwitter.TWITTER_APP_SECRET)
auth.set_access_token(settingsTwitter.TWITTER_KEY, settingsTwitter.TWITTER_SECRET)
api = tweepy.API(auth)
stream_listener = StreamListener()
stream = tweepy.Stream(auth=api.auth, listener=stream_listener)
stream.filter(languages=["en"], track=["#RCBvMI"])
第19行:
引发错误文件“streamTweets.py”,第19行 返回SyntaxError:'return'在函数外部
if (re.findall(self.httpCheck, tweetText) or re.findall(self.httpsCheck, tweetText)):
return