TeCoEd (Teaching Computing Education)
  • Home
    • Freelance
    • Book
    • Downloading
  • Python
    • Learn Python >
      • Python Modules
    • PyGame Zero
    • Python Programs >
      • Higher or Lower
      • Magic Calculator
      • Password Checker
      • Python Pit
    • What's News App
    • Pixels to Cells
    • Python Mosaics
    • Python OCR
    • L-1-AM
    • Web Scraping >
      • Scraping Trains
    • Weather App
    • Snakes and Windows
    • Python Web Server >
      • Flask
    • Python Picks
  • Raspberry Pi
    • All About the Pi
    • Getting Started
    • Remote Desktop and VNC
    • Static IP Address
    • Sonic Pi >
      • 3.14
    • Twitter Feed >
      • Tweepy
    • Android & Pi >
      • Advanced Apps
      • Odds
    • A.I on the the Pi
    • CRON
    • Pick Your Own
  • Pi Hardware
    • Pi HATS >
      • Sense Hat Hacks
      • AstroPi HAT
      • Unicorn-HAT >
        • Unicorn Alphabet Disco
        • Uni Codes / Programs
      • Skywriter
      • Piano HAT
    • STS Pi
    • Pi Camera >
      • Pi-Cam, Python & Email >
        • Time Lapse
      • Pi Noir
    • Pipsta >
      • Flask, Input & Printers
    • Raspberry Pi Power >
      • Energenie IR power
    • Pibrella
    • Distance Sensor
    • LCD Screen
    • Pi-Tooth
    • Robot Arm
    • PiGlow
    • PiFM
    • Accelerometer
    • PiFace >
      • Installing PiFace >
        • Python Commands
  • Pi-Hacks
    • Drone Hacks
    • Pi Glue Gun Hack
    • Blinkt!
    • Sonic Pixels
    • R2D2
    • Get to the chopper
    • Astro Bird
    • Twitter Translator
    • Hacking a Robot
    • Nature_Box >
      • Best Nature Photos
    • Wearable Tech >
      • Project New York
      • P.N.Y Part 2 Health
      • P.N.Y Part 3 Games
      • P.N.Y Part 4 Translation
    • Dino-Tweet
    • Other Links
  • Pi-Hacks 2
    • The Joker
    • Hologram Machine
    • Google Vision: Camera Tell
    • Yoda Tweets
    • Pi Phone
    • Darth Beats
    • Twitter Keyword Finder
    • Crimbo Lights Hack
    • Xmas Elf
    • Halloween 2016
    • Halloween Hack 2015
    • Socrative Zombie
    • Voice Translation
    • The Blue-Who Finder
    • GPIO, Twitter
    • Pi Chat Bot >
      • Dictionary Definitions
    • PiGlow & Email
    • Pibrella Alarm System
    • SMS with Python >
      • Spooking a Mobile
  • Pi-Hacks 3
    • David Bowie
    • Lamp Prank >
      • TEST
    • Yoda FM
    • Retro Player
    • LED Pixel Art
    • TARDIS
    • Battleships
    • LED Board
    • Night Vision
    • Enviro+ Weather
  • Minecraft
    • Minecraft API
    • Minecraft Sweeper
    • PiGlove: Minecraft Power Up
    • Minecraft Photo-booth
    • Rendering Pixels
    • Speed Cube
    • Lucky Dip
  • Computing
    • Why Computing?
    • Can You Compute
    • micro:bit
    • Coding Resources
    • Learn to Code >
      • Coding with iPads
      • Apps Creation Tools
      • sKratchInn
      • Sound Editing
    • Cheat Sheets
    • Theory
    • HOUR OF CODING
    • BEBRAS Computing Challange
    • Computer Facts
    • Free Software and Links
  • Contact Me
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 Sheets

To 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.​
Picture

2. Set up Twitter

To 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. GSpread

Gspread 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 Software

Open the LX Terminal and type:
  • Sudo apt-get update
  • Sudo apt-get upgrade
  • Sudo pip3 install –upgrade gspread
  • Sudo apt-get install python3-oauth2client
  • Sudo pip3 install –upgrade oauth2client

5. The Final Program

The 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.  
Picture
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.
Copyright 2020 TeCoEd @dan_aldred