Loading...
Logo
Processing Forum
icq4ever's Profile
1 Posts
1 Responses
0 Followers

Activity Trend

Last 30 days

Loading Chart...

Show:
Private Message
    I'm already made a program. it's tweetclock.
    it searching tweets within date/time keyword, and displaying whole thing like word clock.
    you can see on browser "http://tweetclock.net/"

    but the problem is super slow.. (especially on web) and also it's freeze when searching.
    so I have to searching with asynchronous way.


    I already searching on google, and only I can find the example code 'asyncUpdatedStatus' from twitter4j.org.
    so I modified my code based on example code. but it's not working. it said 'unexpected token :('
    I'm not heavy java developer. so it's hard to understand about listener.. but I tried..
    please help.


    this is my old one.
    1. Twitter twitter = new TwitterFactory().getInstance();  // twitter setting (not OAuth)
    2. String today_keyword = "오늘은";

    3. void search_today() {
    4.   Query query = new Query(today_keyword);
    5.   query.setRpp(10);
    6.   QueryResult result;
    7.   try {
    8.     result = twitter.search(query);
    9.     List<Tweet> tweet = result.getTweets();
    10.     if(tweet.size() != 0) {
    11.       int n = int(random(tweet.size()));
    12.       today_tweets = tweet.get(n).getText();
    13.       today_tweets = today_tweets.replaceAll("\\n", "");
    14.       int index = today_tweets.indexOf(today_keyword);
    15.       today_t_header = today_tweets.substring(0, index);
    16.       today_t_footer = today_tweets.substring(index + today_keyword.length(), today_tweets.length());
    17.       today_tweets_profileImageURL = tweet.get(n).getProfileImageUrl();
    18.       today_tweets_profileImage = loadImage(today_tweets_profileImageURL, "png");
    19.     } 
    20.     else {
    21.       today_tweets = today_keyword;
    22.       today_tweets_profileImage = loadImage("t.png");
    23.     }
    24.   } 
    25.   catch (TwitterException e) {
    26.     e.printStackTrace();
    27.     println(e.getRateLimitStatus());
    28.   }
    29. }

    this is the new code lines for async processing..
    first I tried to modify code from TwitterFactory to AsyncTwitterFactory.
    it seems like only one time change to Async*, then everything works fine(just my thinking..)
    1. static final Object LOCK = new Object();

      AsyncTwitterFactory factory = new AsyncTwitterFactory();
      AsyncTwitter twitter = factory.getInstance();

      // override function
      TwitterListener listener = new TwitterAdapter() {
        @Override void search(Query query) {
          System.out.println("Successfully searched");
          synchronized (LOCK) {
            LOCK.notify();
          }
        }

        @Override void onException(TwitterException e, TwitterMethod method) {
          if (method == SEARCH) {
            e.printStackTrace();
            synchronized (LOCK) {
              LOCK.notify();
            }
          } 
          else {
      //      synchronized (LOCK) {
      //        LOCK.notify();
      //      }
            throw new AssertionError("Should not happen");
          }
        }
      };

      twitter.addListener(listener);  // processing said. unexpected token: (