I am interested to know who the new Doctor Who is going to be. Twitter tends to break a lot of news before other media. Even if it is not all official, there is a lot of chatter prior to a significant announcement. I have used the Python Twitter API before to stream Tweets and look for keywords in my stream and I was aware that you can create more advanced programs to manipulate keywords and phrases. Spread sheets also appeal to me and I wondered if there was a method to write the 'found Tweets' to a spread sheet, well yes there is.
So this program asks you for a keyword, for example, "the next Dr Who is....", "The new James Bond is".... A JSON file of all the 'found' tweets is downloaded and then each Tweet is printed out. Each of the individual Tweets is then uploaded to a Google Sheet, which displays the key words, data and the running total as well as the Tweet. This hack also has an added Doctor Who Alarm which will surely appeal the the Who Fans out there! Each time a keyword Tweet is found the TARDIS is triggered! |
|
1. Set up Google SheetsTo interact with Google Sheets you will need to follow a few steps to create an authentication. This basically involves setting up a Google API and creating some 'keys', these are exported as a JSON file which is stored and accessed by the Python code to authenticate with the Spreadsheet. There is an excellent guide here which is easy to follow.
|
2. Set up TwitterTo manipulate and stream tweets from Twitter you also require an authentication. I have a simple guide to the set up here Or check out the Raspberry Pi Foundations guide which is very simple and straight forward. This can be found here:
4. GSpreadGspread is the main Python Module for interacting and manipulating the Google Sheet. It can be download from here. This page is updated and contains the main codes to edit the sheet.
Updating a cell is easy and uses the code: worksheet.update_acell('B1', 'Bingo!') This will update cell B1 with the word Bingo. You can also create new sheets, delete values and much much more more. |
3. Install the SoftwareOpen the LX Terminal and type:
5. The Final ProgramThe final program searches for Tweets with the keyword and returns them. They are then written to the Spreadsheet one at a time and can be shared and viewed with other users.
|
You can view the live Google Sheet at here Send me a Tweet at @dan_aldred if you want me to run a specific Keyword search.