How to continuously search for a twitter hashtag in Processing

edited December 2014 in Library Questions

Hi all, I am working on a project that requires Processing to continuously search for twitter hashtag. I've figured out how to search for multiple hashtags at one time but am still confused with how to modify the code below to meet my need. Anyone can help? Much thanks!

    import twitter4j.conf.*; 
    import twitter4j.api.*; 
    import twitter4j.*; 
    import java.util.*;  
    import ddf.minim.*;
    float z = 0;
    float a = 0;
    PImage bg;
    float theta1 = PI/2;
    String name = "";
    String msg = "";
    boolean stopr = true;
    PImage img;

    ConfigurationBuilder cb; 
    Query query1; 
    Query query2;
    Query query3;
    Query query4;
    Twitter twitter;
    AudioPlayer player;
    Minim minim;

    void setup() {
      size(508, 512); 
      img = loadImage("");
      imageMode(CENTER);
      minim = new Minim(this);
      player = minim.loadFile("", 1024);
      player.play();
      player.loop();


      cb = new ConfigurationBuilder();      //Acreditacion
      cb.setOAuthConsumerKey("");   
      cb.setOAuthConsumerSecret("");   
      cb.setOAuthAccessToken("J");   
      cb.setOAuthAccessTokenSecret("");

      twitter = new TwitterFactory(cb.build()).getInstance();    
      queryTwitter();
    } 



    void queryTwitter() {   
      //Search for four hashtags on Twitter
      query1 = new Query("#nyu");  
      query2 = new Query("#nyc"); 
      query3 = new Query("#acbuilding");
      query4 = new Query("#Inthecity");

      query1.setCount(1);   
      query2.setCount(1);  
      query3.setCount(1);
      query4.setCount(1);

      //Start searching
      try {  
      QueryResult result1 = twitter.search(query1);  
      QueryResult result2 = twitter.search(query2);
      QueryResult result3 = twitter.search(query3);
      QueryResult result4 = twitter.search(query4);

      //Get a list of data from Twitter
       ArrayList tweets1 = (ArrayList) result1.getTweets();
       ArrayList tweets2 = (ArrayList) result2.getTweets();
       ArrayList tweets3 = (ArrayList) result3.getTweets();
       ArrayList tweets4 = (ArrayList) result4.getTweets(); 

      //Confirm if 
      for (int i = 0; i < tweets1.size(); i++) {
        Status t = (Status) tweets1.get(i);
        User user = t.getUser();
        name = user.getName();
        //boolean a = boolean(name);
        msg = t.getText();
        //boolean b = boolean(msg);
        println(name + ": " + msg);
    }


      for (int i = 0; i < tweets2.size(); i++) {
        Status t = (Status) tweets2.get(i);
        User user = t.getUser();
        name = user.getName();
        //boolean c = boolean(name);
        msg = t.getText();
        //boolean d = boolean(msg);
        println(name + ": " + msg);
    };

    } 

      catch (TwitterException te) {     
        println("Couldn''t connect: " + te);
      }
    }


    void draw(){

        z = a + z;

        bg = loadImage("clock.jpg");
        background(bg);
        image(img, width/2 - img.width/2, height - img.height/4);
        //strokeWeight(30);
        //stroke(255, 0, 0);
        pushMatrix();
        translate(width/2, height/2);
        rotate(z);
        image(img, 0, 0);
        //line(0, 0, 0, -height/2);
        popMatrix();

        if (name != "" && msg != "") {
        stopr = false;
        } else {
        stopr = true;
        }

        if (stopr == false) {
          a = 0.01;
        }

       if (stopr == true) {
         a = 0;
       }

    } 

Answers

Sign In or Register to comment.