Processing and Twitter

Screen shot 2013-03-06 at 1.06.42 AM

Recently I’ve been looking into creating some design that is heavily reliant on code and coding. I’m absolutely amazed by all the people out there willing to post the entire code of their sketches, or post regularly to help forums.. I don’t think I’d be able to get through an inch of the world of code without all these amazing and helpful people. Which got me to thinking that perhaps in return when I stumble on things that work I should also share my learning with people so they can gain from it too.

So, this week I was interested in collecting data off of twitter through processing. I found a really straight forward tutorial by Jer Thorp and through tinkering for a few hours I was able to get the sketch to function and collect tweets #Tasmeem.

This is the link to the original post, where you can find all the steps. I am only going to be writing about the things I needed to tweak to get it to run for me, and where I found those tweaks online:

http://blog.blprnt.com/blog/blprnt/updated-quick-tutorial-processing-twitter

Regarding the twitter oAuth process there are a few steps that are different, but its not something you can’t just messing around and figure out. Don’t forget you need all four codes for this to run.

To import the twitter4j library you can’t just simply drag and drop the file into the sketch as is it mentioned on Jer’s blog. You need to manually install the library following the steps listed here:

http://wiki.processing.org/w/How_to_Install_a_Contributed_Library

Here is an image, all the highlighted text had to be edited after I unzipped the twitter4j file, and placed into my sketch folder.

Screen shot 2013-03-07 at 12.16.51 AM

Over and over again I got the error “Cannot find a class or type named Tweet”. I found two really helpfully links:

https://forum.processing.org/topic/twitter4j-error-cannot-find-a-class-or-type-named-configuration-builder

http://stackoverflow.com/questions/14510641/twitter4j-not-recognizing-setrpp-or-tweet-class

Which made me add the following code:

import twitter4j.*;

import twitter4j.conf.*;

And switch out the lines of code about Tweet t = (tweet).. to:

Status t=(Status) tweets.get(i);
User u=(User) t.getUser();
String user=u.getName();

[If you are getting an error about setRpp the last link above had a solution to that also, I didn't]

Here is the edited code:

import twitter4j.*;

import twitter4j.conf.*;

import java.util.List;

//Build an ArrayList to hold all of the words that we get from the imported tweets
ArrayList<String> words = new ArrayList();

void setup() {
  //Set the size of the stage, and the background to black.
  size(1300,800);
  background(0);
  smooth();

  //Credentials
  ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("XXXXXXXXXXXXXXXXXXX");
cb.setOAuthConsumerSecret("XXXXXXXXXXXXXXXXXXX");
cb.setOAuthAccessToken("XXXXXXXXXXXXXXXXXXX");
cb.setOAuthAccessTokenSecret("XXXXXXXXXXXXXXXXXXX");

  //Make the twitter object and prepare the query
  Twitter twitter = new TwitterFactory(cb.build()).getInstance();
  Query query = new Query("#tasmeem");

  //Try making the query request.
  try {
    QueryResult result = twitter.search(query);
    ArrayList tweets = (ArrayList) result.getTweets();

    for (int i = 0; i < tweets.size(); i++) {
Status t=(Status) tweets.get(i);
User u=(User) t.getUser();
String user=u.getName();
      String msg = t.getText();
      Date d = t.getCreatedAt();
      println("Tweet by " + user + " at " + d + ": " + msg);
      //Break the tweet into words
      String[] input = msg.split(" ");
      for (int j = 0;  j < input.length; j++) {
       //Put each word into the words ArrayList
       words.add(input[j]);
      }
    };
  }
  catch (TwitterException te) {
    println("Couldn't connect: " + te);
  };
}

void draw() {
  //Draw a faint black rectangle over what is currently on the stage so it fades over time.
  fill(0,1);
  rect(0,0,width,height);

  //Draw a word from the list of words that we've built
  int i = (frameCount % words.size());
  String word = words.get(i);

  //Put it somewhere random on the stage, with a random size and colour
  fill(255,random(50,150));
  textSize(random(10,30));
  text(word, random(width), random(height));
}

Advertisements

Day 53 – Connect The Dots

Again, you can’t connect the dots looking forward; you can only connect them looking backwards. So you have to trust that the dots will somehow connect in your future. You have to trust in something – your gut, destiny, life, karma, whatever. This approach has never let me down, and it has made all the difference in my life.

Steve Job

It wasn’t until a few weeks after Amsterdam that I realized that I wanted to change my thesis direction. It wasn’t until after the semester had ended that I found this image from my trip to Amsterdam. Out of all the totem poles in that park I only photographed that one, I only cared about that one.. It seems to me looking back on a great many things in my life that I’ve always been headed in the same direction. Perhaps its time I stopped worrying about where I am going and starting trusting that I’ll get there regardless.

Design Studio One: Open Design (Part Two): Fab-Shoes

 

 

For the second half of the Open Design project in our studio one class we as groups exchanged projects. Our group inherited the Open Design shoe file. We decided we wanted to go two different directions with the project, one would be making a 3D printed heel, and the other would be modernizing a traditional Arab mens sandal. We ended up with two files for the heel, an illustrator file for the upper, and a Rhino file for the wedge, both files can be edited and printed at any fab lab in the world. The idea for the second shoe was actually to use an Eskafi (shoe makers) to build a shoe for us, and so we would be considering the labor of one man equivalent to the machines in a fab lab. But they actually didn’t have an Eskafi’s in Qatar (weird?) so we had to modify our idea and use a local shoe factory to assemble our shoe (which kind of makes it not an open design project, but there is nothing we could do about it..). For the sandal we created a basic illustrator upper that can easily be modified and cut.

Design Studio One: Open Design (Part One): PEPACAM

Throughout last semester we worked in groups in our design studio one class to create two open design projects. Open Design is a type of design that is based off of the principles of open source sharing of information, it basically means to create a digital file that people can then use as is, or edit, then print/cut at home or in a fabrication lab. Ronen Kadushin’s name was used a lot in our class 😉

For the first part of the project each group came up with their own idea for an open design product. My group at first was really interested in the theme of travel, after we talked about the concept of travel for a while we deconstructed it into the activities that go on during travel. We ended up discussing photography as a big activity for most travelers, then we decided to examine photography in itself. Noticing that analog photography is actually a big trend right now (Lomography) we decided to build a pinhole camera using the Pepakura folding technique we learned in our fabrication class. The file we created is the most basic shape that we could think of, the idea is to allow users to expand off our simple design and do what ever they want with it. We named it Pepacam.

Though its really simple, this was my favorite project of the semester.