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 :)
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"])
