DEV Community

Discussion on: Sentiment analysis on Trump's tweets using Python 🐍

Collapse
 
r0f1 profile image
Florian Rohrer

Thank you for your tutorial! Its was easy to follow and everything work on my first attempt!

I do not want to reload all the tweets from the web, while I am developing. I altered the first few lines, to cache the tweets locally.

save = "saved.pickle"
if os.path.exists(os.path.join(os.path.dirname(__file__), save)):
    with open(save, 'rb') as f:
        tweets = pickle.load(f)
else:
    extractor = twitter_setup()
    tweets = extractor.user_timeline(screen_name="realDonaldTrump", count=200)
    with open(save, 'wb') as f:
        pickle.dump(tweets, f)
Collapse
 
rodolfoferro profile image
Rodolfo Ferro • Edited

Excellent idea!

What I did at the end (in my personal case) was to save the tweet list as a csv file (data.to_csv(...)), taking as an advantage that I already had all the info in a pandas dataframe. :)

Thanks for your great comment!