We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › translator needed
Page Index Toggle Pages: 1
translator needed (Read 1584 times)
translator needed
Jun 23rd, 2009, 12:44am
 
Hello. I'm trying to do some experiments with data derived from twitter search queries. I found the following code that works but needs to be translated into processing. I've spent a couple hours looking at it with no luck (my hacking has its limits). Can anyone help me?  My goal is to extract the text containing the associated search from each list entry and drop everything else. Any help would be much appreciated!!!   Cheesy

  Twitter twitter = new Twitter();
  Query query = new Query("source:twitter4j thinking");
  QueryResult result = twitter.search(query);
  System.out.println("hits:" + result.getTotal());
  for (Tweet tweet : result.getTweets()) {
      System.out.println(tweet.getFromUser() + ":" + tweet.getText());
  }
Re: translator needed
Reply #1 - Jun 23rd, 2009, 1:19am
 
It might help to post the source of the code you've posted...  You're also not going to get far without the relevant library.

"Twitter twitter = new Twitter();" creates a new 'Twitter' object so you'd need the library that defines that Class, or would have to convert it to Processing: i.e. you can't simply 'translate' this code into Processing and expect it to work - there's a whole lot more going on here...

As it happens a quick search of one of the lines of code gave me this.  It's a Java library which in theory I assume you could access from Processing, but I'm afraid I don't have any experience of that...  So I could quite easily be wrong.
Re: translator needed
Reply #2 - Jun 23rd, 2009, 2:00am
 
getTweets returns a List. this should do it

 try
 {
   Query query = new Query("source:twitter4j thinking");
   QueryResult result = twitter.search( query );
   System.out.println("hits:" + result.getTotal());
   
   List tweets = result.getTweets();
   for( int i=0; i<tweets.size(); i++ )
   {
       Tweet tweet = (Tweet)tweets.get( i );
       System.out.println(tweet.getFromUser() + ":" + tweet.getText());
   }              
 } catch (TwitterException te) {
     System.out.println("Failed to get queries: " + te.getMessage());
     System.exit( -1);
 }


or with iterators

replace the for-loop with:

   for( Iterator it = tweets.iterator(); it.hasNext(); )
   {
     Tweet tweet = (Tweet)it.next();      
       System.out.println(tweet.getFromUser() + ":" + tweet.getText());
   }
Re: translator needed
Reply #3 - Jun 23rd, 2009, 6:11am
 
All of the Twitter code will work as is inside processing. You'll need the Twitter4j library, however. Check out the link blindfish posted, download the library, and simply add the twitter4j.jar file to your sketch, and you're ready to rock. After that, a lot of the code and methods are pretty self-explanatory, and you'll be able to find sample code all over the place.
Re: translator needed
Reply #4 - Jun 23rd, 2009, 6:46am
 
no it won't.

"We currently only support Java 1.4 (and earlier) syntax. You cannot currently use 1.5 syntax in the Processing Development Environment. This means no generics, templates, enum, varargs, foreach, and the rest"
Page Index Toggle Pages: 1