Reputation: 1
I am trying to write a tweet to a text file. However, it is cut off if the tweet is too long. Example, one of the longer tweet_body samples looks like this:
"Is this a new line? Is this a new line? Is this a new line? Is this a new line? Is this a new line? Is this a new (link to tweet is here, not sure why)"
How do I get it so it will write the entire tweet? My code:
def on_data(self, data):
tweet = json.loads(data)
user = json.dumps(tweet['user']['screen_name'])
tweet_body = json.dumps(tweet['text'])
with open('results.txt', 'a') as tf:
tf.write('\n @ ' + user + ' ' + tweet_body)
Upvotes: 0
Views: 1745
Reputation: 429
Personally I would recommend using the api search method, it does everything the searching method you are currently using does. You can search in extended mode which will solve your issue of the tweets being cut off.
for tweet in tweepy.Cursor(api.search, q='giveaway, tweet_mode='extended').items(10):
You can save all the tweets data into variables like so:
# Defining Tweets Creators Name
tweettext = str( tweet.full_text.lower().encode('ascii',errors='ignore')) #encoding to get rid of characters that may not be able to be displayed
# Defining Tweets Id
tweetid = tweet.id
# Defining Tweets Creators User Id
userid = tweet.user.id
Upvotes: 2