I have a project in python that I am trying to run from IDLE using Python 2.7 When I run the program a text file does get created like I want, but is not getting any information written to it and I do not understand why this is happening. I am running it as a module by pressing the F5 key in IDLE on my Ubuntu 12.04 LTS laptop.
Here is the code:
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'])
My file on github if anyone wants to work on it with me on github:
stocktwitterdb.py
A streaming example using tweepy can be found here on github:
tweepy streaming.py
Now that I have things coming across the shell I want to put them to a database or a text file.
There’s been some confusion in the changes you need to make, so I’m going to post a hopefully-fixed version here, along with some comments about why things are the way they are.