from twitter import *
# Change to your keys
oauth_token = "aaa"
oauth_secret = "bbb"
consumer_key = "ccc"
consumer_secret = "ddd"
with open('football_terms.txt') as f:
vocab = [term.replace('\n', '') for term in f.readlines()]
with open('football_teams.txt') as f:
for line in f:
vocab.append(line.replace('\n', ''))
track_params = ','.join(vocab)
twitter_stream = TwitterStream(auth=OAuth(oauth_token,
oauth_secret,
consumer_key,
consumer_secret))
iterator = twitter_stream.statuses.filter(track=track_params,language='en')
for tweet in iterator:
if 'text' in tweet:
print tweet
执行程序时,会出现错误NameError:' TwitterStream'没有定义 即使安装了Twitter 1.15
之后