# Finding topics of interest by using the filtering capablities it offers. import twitter, json, sys, csv # == OAuth Authentication == # The consumer keys can be found on your application's Details # page located at https://dev.twitter.com/apps (under "OAuth settings") # this app is being run by cast laboratory..@CASTlaboratory (4003669463) consumer_key="" consumer_secret="" # 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="" access_token_secret="" auth = twitter.oauth.OAuth(access_token, access_token_secret,consumer_key, consumer_secret) twitter_api = twitter.Twitter(auth=auth) csvfile = open('3.csv', 'a') csvwriter = csv.writer(csvfile) # what does following a user mean - https://dev.twitter.com/streaming/overview/request-parameters#follow u = "18949452, 612473" print >> sys.stderr, 'Filtering the public timeline for a user="%s"' % (u) # Reference the self.auth parameter twitter_stream = twitter.TwitterStream(auth=twitter_api.auth) # See https://dev.twitter.com/docs/streaming-apis stream = twitter_stream.statuses.filter(follow=u) # For illustrative purposes, when all else fails, search for Justin Bieber # and something is sure to turn up (at least, on Twitter) for tweet in stream: print (tweet['text']) user = tweet['user']['screen_name'] # print (json.dumps(tweet, indent=1)) csvwriter.writerow([tweet['created_at'],user,tweet['text']])