Goal of Python Code:
- To scan twitter for various hashtags, send a signal to an Arduino which then signals an assigned audio input once someone tweets with a hashtag
The twitter API utilizes JSON but we chose to write our code in Python, so we needed a “translator” so we could interface with Twitter easily. Tweepy allows this translation, so all you need to do is download, authenticate and import the library.
Problems and Solutions:
- One of the earliest problems we ran into was integrating Tweepy into our code because we needed to renew our authentication and we were using an outdated instruction manual for our version of Tweepy.
The basic_auth.py on the Tweepy github page was different than the one that downloads with the library, so it tooks us a while to realize this and then update our methods.
- Simplifying the code so that it reads all of twitter and only recognizes hashtags, rather than “printing” all of the data associated with each tweet.
When we were first experimenting, our code basically threw up all of the data associated with each hashtag: the user info, tweet itself, and time stamp. If this was something we would distribute to the public, this might be something that needs to be changed, but we decided it wasn’t exactly a “problem”, but more of a design suggestion for the future.
- Finding a solution to enable the code to scan for multiple hashtags at once and then send signals to a specific serial port on the Arduino, rather than any hashtag triggering any serial port.
- Example: #yolo needs to trigger serial port 2, while #lybia needs to trigger serial port 4, etc
In order to run several processes at once, Belinda’s original idea was to incorporate “subprocesses”. There were a few options for subprocess libraries that allowed us to “spawn new processes, connect to their input/output/error pipes, and obtain their return codes. Even though this would have been a solution, Andy informed us that creating a list, or array, would be a more elegant solution.
This was our final solution for our python script: