Quantcast
Viewing latest article 1
Browse Latest Browse All 2

Answer by Mickaël Martinez for Tweepy, how to pull count integer and use it

Opening the file with the write mode erases its previous data so, if you want to add each new tweet to the file, you should use the append mode instead.

As an alternative, you could also store all the tweets' json in a list and write them all at once. That should be more efficient and the list at the root of your json file will make it valid.

json_tweets = []for tweet in cursor.items():    json_tweets.append(tweet._json)with open("Tweet_Payload.json", "w") as outfile:    outfile.write(json.dumps(json_tweets,indent=4, sort_keys=True))

On a side note, the with closes the file automatically, you don't need to do it.


Viewing latest article 1
Browse Latest Browse All 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>