내가 감정 분석을위한 실버에 관한 짹짹의 트위터 스트림을 필터링하기 위해 노력하고 ...파이썬 - 트위터 스트림. 필터 튜플 오류
class listener(StreamListener):
def on_data(self, data):
try:
tweet = json.loads(data)
print (tweet['created_at'], tweet['text'])
alchemyapi = AlchemyAPI()
response = alchemyapi.sentiment('text', tweet['text'])
print "Sentiment: ", response["docSentiment"]["type"]
dictionary={}
dictionary['tweet'] = tweet['text']
dictionary['id'] = tweet['id']
dictionary['created_at'] = tweet['created_at']
dictionary['sentiment'] = response["docSentiment"]["type"]
json_data = json.dumps(dictionary)
saveFile = open('silverTweetFeed.json','a') #a=append
saveFile.write(json_data)
saveFile.write('\n')
saveFile.close()
return True
except BaseException, e: #baseException because there may be a rate limit or internet drop
print 'failed ondata,',str(e)
time.sleep(5)
def on_error(self, status):
print status
auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken,asecret)
twitterStream = Stream(auth, listener())
twitterStream.filter(track=["silver" and "CFD" or "invest" or "bloomberg" or "DFT" or "rally"or
"hike" or "investors" or "demand" or "interest rate" or "inflation" or
"bullion" or "trading" or "investment" or "market"])
twitterStream.filter(languages=["en"])
하지만이를 실행할 때 오류가 발생합니다 ...
/PythonFiles/silverScript.py", line 49, in <module>
"investors", "demand", "interest rate", "inflation", "bullion", "trading", "investment", "market")])
File "build/bdist.macosx-10.9-intel/egg/tweepy/streaming.py", line 330, in filter
AttributeError: 'tuple' object has no attribute 'encode'
logout
누구든지보다 효율적인 필터 기술을 제안하거나이 오류를 해결할 수 있습니까?
이 작업을 수행 할 수 있는지 여부가 확실하지 않습니다. 필자는 논리 연산자 '또는'을 사용하여 시도했지만 동일한 오류가 발생했습니다 – Adam