简体   繁体   中英

Tweepy tweet text is cut off

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM