Finding More Elegant Solutions for the ECHO Python Script

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.

Python Twitter Script Throwup

Python Twitter Script Throw Up

  • 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:

Python Script for ECHO

Python Script for ECHO

Advertisements

Finding Early Solutions and A Lot More Problems

We finalized our plan and finished our proposal document. Originally started with VH Mutant Subtitles as our name, but after a brainstorming session we changed it to something more reminiscent of our project purpose– E.C.H.O (Emerging Chatter Heuristic Operator). “Emerging” refers to the immediacy of the twitter posts; “Chatter” refers to the unending stream of droning information that spews from the social media outlets; “Heuristics” describes the project’s goal, to translate the unnoticeable droning on the internet into audible sound; and “Operator” refers to the arudino itself, it is the instigator of our little social experiment.

Will and Robert talked shop about the conceptual side of the production and are looking for transistors. The sound system will have 6 channels comprised from 3 cassette players with Left/Right outputs. Aside from the wires, we tried to figure out what the thing will look on the outside – but that’s still pretty vague.

Alex started writing a formal justification for our project by connecting our intentions with past readings and documenting our progress in a more comprehensive manner.

Belinda worked on the code, and tried to get the script to capture hastags instead of a home twitter timeline that we used in our original project. As always, the internet is a wonderful place and we found an already written program to help us with this side of the project. It’s called Tweepy and it’s a Twitter API library that may be invaluable to us in the coming weeks, at least that’s what we hope.

You can find it here: https://github.com/tweepy/tweepy
It supports Python 2.5 and up but not Python 3.

from tweepy.streaming import StreamListener
from tweepy import OAuthHandler

Future Goals

We need to know how much current has to pump through the transistors to power our speakers. This might be one of our earliest snags in the design. There were a lot of sites that detailed HOW to use the transistors in this way, but not really WHERE to get them or the specific models. After a bit more searching, we learned we need to use a FET (field effect transistor) and change our code to accommodate this. The way we did it before (on a BJT), the channel closes when you add a current, but a FET closes when you take current away. We need to switch it so the script turns it ON instead of OFF.

In our last project, the code was one of the hardest parts but now it seems this project will have a much heavier on hands component that may prove challenging.