Twitter Client for Excel with Python and DataNitro
Monday, August 06, 2012Tweet
In this blog post I am going to show how I built NitroBird - a Twitter client for Excel - using Python, tweepy and DataNitro. NitroBird updates Excel worksheets with tweets as they are posted, lets you tweet from a worksheet as well as search and browse other user's profile. See the code on Github or download a zip file with everything ready to run (Excel Worksheet, Python script and tweepy library).
Not everyone has the pleasure (?!) to spend all day at work on Twitter, and if you happen to occasionally work in Excel, I'm sure this worksheet will help you avoid suspicious looks from your colleagues or boss :-) If that's not the case, then at least this example will demonstrate how easy it is to connect Excel with external data sources using Python and DataNitro.
There are multiple Twitter Python libraries. I've used tweepy, which is extensively documented here. First, we have to deal with Twitter OAuth:
- Set up your app keys. Go to developer.twitter.com, create a new app (with read and write privileges) and obtain your consumer key and consumer secret.
- Open twitter.xlsx in MS Office 2007/2010, go to the settings sheet and input your new keys in cells
B12and B13(by the time you read this, the keys provided by default will have probably been invalidated or will have exceeded Twitter rate limits).
- Import nitrobird.py on the DataNitro tab.
- Click 'Run'.
- Click the auto generated link and authorize the app to read & write.
- Copy & paste the authentication code into cell B5
After these steps you should be ready to go and your settings worksheet will look like this:
You can now go the "profile" sheet to see your Twitter profile, your followers, friends and past tweets. After clicking the yellow "tweet" cell, NitroBird will post the content of cell D5 to your Twitter timeline:
An uninitiated eye looking at your "work" spreadsheet won't be able to tell that you're browsing Twitter, as your entire timeline is just a spreadsheet with tweets (updated every 2 minutes, or you can click 'refresh' to force it manually):
Lastly, you can search for specific tweets on the "search" sheet and browse other user's profile on the "user" sheet. Feel free to tweak the code to your needs and enjoy your Twitter in Excel!