Hello everyone! Im new here and im also new to python. Im eager to learn python because the possibilities are immense. Currently im working on a twitter streaming code, which I pasted in the code section below.
Im wondering how I should exclude data from the streamer?
1. For instance, i want to check wether the 'status' or 'location' fields are not null.
2. I would like to exclude some fields. For instance, 'retweets'.
If someone could explain how I'm supposed to program [1] en [2] then I would be very happy :)
Im wondering how I should exclude data from the streamer?
1. For instance, i want to check wether the 'status' or 'location' fields are not null.
2. I would like to exclude some fields. For instance, 'retweets'.
If someone could explain how I'm supposed to program [1] en [2] then I would be very happy :)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
from tweepy import Stream from tweepy import OAuthHandler from tweepy.streaming import StreamListener import json # consumer key, consumer secret, access token, access secret. consumer_key = "xxx" consumer_secret = "xxx" access_token = "xxxx" access_token_secret = "xxxx" class StdOutlistener(StreamListener): def on_data( self , data): json_data = json.loads(data) print (json_data) # Open json text file to save the tweets with open ( 'tweets.json' , 'a' ) as tf: tf.write(data) return True def on_error( self , status): print (status) auth = OAuthHandler(consumer_key, consumer_secret) auth.set_access_token(access_token, access_token_secret) twitterStream = Stream(auth, StdOutlistener()) twitterStream. filter (track = [ "Test" ]) |