Python 2.7 を使用して IDLE から実行しようとしている Python のプロジェクトがあります。プログラムを実行すると、必要なようにテキスト ファイルが作成されますが、情報が書き込まれず、なぜこれが起こっているのかわかりません。 . Ubuntu 12.04 LTS ラップトップの IDLE で F5 キーを押して、モジュールとして実行しています。
コードは次のとおりです。
import time
import MySQLdb
import tweepy
from tweepy.streaming import StreamListener
from tweepy import OAuthHandler
from tweepy import Stream
# Go to http://dev.twitter.com and create an app.
# The consumer key and secret will be generated for you after
consumer_key=" # Omitted "
consumer_secret=" # Omitted "
# After the step above, you will be redirected to your app's page.
# Create an access token under the the "Your access token" section
access_token=" # Omitted "
access_token_secret=" # Omitted "
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
# If the authentication was successful, you should
# see the name of the account print out
print api.me().name
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
print data
return True
def on_error(self, status):
print status
if __name__ == '__main__':
l = StdOutListener()
stream = Stream(auth, l)
stream.filter(track=['#google'])
誰かが github で私と一緒に作業したい場合は、github の私のファイル: stocktwitterdb.py
tweepy を使用したストリーミングの例は、github の tweepy streaming.pyにあります。
シェルに出くわしたものがあるので、それらをデータベースまたはテキスト ファイルに入れたいと思います。