Example usage for twitter4j Status getText

List of usage examples for twitter4j Status getText

Introduction

In this page you can find the example usage for twitter4j Status getText.

Prototype

String getText();

Source Link

Document

Returns the text of the status

Usage

From source file:chillerbot.ChillTweet.java

public void retweetEveryColorBot() throws TwitterException {
    for (Status each : getStatusesFromUser("@everycolorbot")) {
        String[] statusText = (each.getText().replace("0x", "#").split(" "));
        TweetCandidate candidate = convert
                .nameAndLinkForColor(new Color(Integer.parseInt(statusText[0].substring(1), 16)));
        if (evaluateTweet(candidate)) {
            System.out.println("tweeting " + candidate.toString());
            reTweetPassedCandidate(candidate, each.getText());
            return;
        }/* ww  w. j  av a2s  .  c o  m*/
    }
}

From source file:chillerbot.ChillTweet.java

private boolean inLatestTweets(String name) {
    String[] nameParts = name.split(" ");
    // I'm reading your timeline

    for (Status each : this.homeTimeline) {
        String text = each.getText();
        if (!text.contains("called")) {
            return false;
        }/*from  w ww.j a  v  a 2  s.c o  m*/
        text = text.substring(text.indexOf("called"), text.indexOf("And"));
        if (text.contains(nameParts[0]) || text.contains(nameParts[1])) {
            System.out.println(name + " found from latest tweets");
            return true;
        }
    }
    return false;
}

From source file:Classes.TwitterPull.java

public void retrieveTweets() throws TwitterException {
    Query query = new Query("\"" + this.queryString + "\"");
    query.setLang("en");
    query.setCount(100);//from w ww . ja  va2s.c  o  m
    QueryResult result;
    int i = 0;
    do {
        result = twitter.search(query);
        List<Status> tweets = result.getTweets();
        for (Status tweet : tweets) {
            String t = tweet.getText().replaceAll("\n", "").replaceAll("\r", "");
            //                appendTweetDocument(t);
            retrievedTweets.add(t);
        }
        i++;
    } while ((query = result.nextQuery()) != null && i < 50);

}

From source file:clientetwitter.ClienteTwitter.java

public static void ReadTimeLine() throws TwitterException {

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey("ZpF1TSpAyQlBLMN7egUz3uT3D")
            .setOAuthConsumerSecret("r2icg36QB6G862Re2IvwHNGuDK25z5awKSeNG9kV9LRpcAmuOW")
            .setOAuthAccessToken("4314010284-QGXKFbFQ5TK4zqbplRsfoP0wL6NTv7bsMJypWex")
            .setOAuthAccessTokenSecret("4v61YXTkzM3Kob0xAHu59ISgM0fTKSLrOuDXTG5ctX7rr");

    TwitterFactory tf = new TwitterFactory(cb.build());
    twitter4j.Twitter tw = tf.getInstance();

    //reading//ww w . ja  v a 2s .com
    List<Status> statuses = tw.getHomeTimeline();
    for (Status status1 : statuses) {
        System.out.println(status1.getUser().getName() + ": " + status1.getText());
    }

}

From source file:cloudcomputebot.Input.Decipher.java

License:Open Source License

public static void handleInput(Status status, User sender)
        throws FileNotFoundException, IOException, TwitterException {
    String[] lines = argsNoComments(status.getText());
    if (lines.length > 0) {
        String cmd = lines[0];//w  w  w.  j a v a2  s . c om
        if (cmd.equalsIgnoreCase(validCmds[0]) || cmd.equalsIgnoreCase(validCmds[1])) {
            String[] fractalInputStream = new String[lines.length - 1];
            int c = 0;
            for (int i = 1; i < lines.length; i++) {
                fractalInputStream[c] = lines[i];
                c++;
            }
            ImageCreator fractalCreator = new ImageCreator();
            fractalCreator.setArgsForTwitter(fractalInputStream);
            BufferedImage fractal = fractalCreator.drawFractal();
            StatusUpdate retweet = new StatusUpdate("@" + sender.getScreenName());
            File img = new File("image.gif");
            ImageIO.write(fractal, "gif", img);
            retweet.setMedia(img);
            CloudComputeBot.t.updateStatus(retweet);
        }
    }
}

From source file:cloudcomputebot.MentionListener.java

License:Open Source License

@Override
public void onStatus(Status status) {
    System.out.println(status.getUser().getScreenName() + ": " + status.getText());
    try {//from  w  ww . java2  s  . c om
        Decipher.handleInput(status, status.getUser());
    } catch (IOException ex) {
        Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex);
    } catch (TwitterException ex) {
        Logger.getLogger(MentionListener.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:co.cask.cdap.template.etl.realtime.source.TwitterSource.java

License:Apache License

private StructuredRecord convertTweet(Status tweet) {
    StructuredRecord.Builder recordBuilder = StructuredRecord.builder(this.schema);
    recordBuilder.set(ID, tweet.getId());
    recordBuilder.set(MSG, tweet.getText());
    recordBuilder.set(LANG, tweet.getLang());
    Date tweetDate = tweet.getCreatedAt();
    if (tweetDate != null) {
        recordBuilder.set(TIME, tweetDate.getTime());
    }//  w ww.  j a  v  a 2 s.  co m
    recordBuilder.set(FAVC, tweet.getFavoriteCount());
    recordBuilder.set(RTC, tweet.getRetweetCount());
    recordBuilder.set(SRC, tweet.getSource());
    if (tweet.getGeoLocation() != null) {
        recordBuilder.set(GLAT, tweet.getGeoLocation().getLatitude());
        recordBuilder.set(GLNG, tweet.getGeoLocation().getLongitude());
    }
    recordBuilder.set(ISRT, tweet.isRetweet());
    return recordBuilder.build();
}

From source file:co.cask.hydrator.plugin.realtime.source.TwitterSource.java

License:Apache License

private StructuredRecord convertTweet(Status tweet) {
    StructuredRecord.Builder recordBuilder = StructuredRecord.builder(SCHEMA);
    recordBuilder.set(ID, tweet.getId());
    recordBuilder.set(MSG, tweet.getText());
    recordBuilder.set(LANG, tweet.getLang());
    Date tweetDate = tweet.getCreatedAt();
    if (tweetDate != null) {
        recordBuilder.set(TIME, tweetDate.getTime());
    }//from  w  w  w .  j a va2  s.  co m
    recordBuilder.set(FAVC, tweet.getFavoriteCount());
    recordBuilder.set(RTC, tweet.getRetweetCount());
    recordBuilder.set(SRC, tweet.getSource());
    if (tweet.getGeoLocation() != null) {
        recordBuilder.set(GLAT, tweet.getGeoLocation().getLatitude());
        recordBuilder.set(GLNG, tweet.getGeoLocation().getLongitude());
    }
    recordBuilder.set(ISRT, tweet.isRetweet());
    return recordBuilder.build();
}

From source file:co.cask.tigon.analytics.TweetCollector.java

License:Apache License

@Tick(unit = TimeUnit.MILLISECONDS, delay = 100)
public void collect() throws InterruptedException {
    if (this.queue == null) {
        // Sleep and return if public timeline is disabled
        Thread.sleep(1000);//  w w  w . j  a v  a  2  s . c  o  m
        return;
    }
    int batchSize = 100;

    for (int i = 0; i < batchSize; i++) {
        Status tweet = queue.poll();
        if (tweet == null) {
            break;
        }

        // emitting more data to get higher throughput
        for (int k = 0; k < tweetAmplification; k++) {
            List<String> hashtags = Lists.newArrayList();
            for (HashtagEntity hashtag : tweet.getHashtagEntities()) {
                hashtags.add(hashtag.getText());
            }
            output.emit(new SimpleTweet(tweet.getText(), hashtags));
        }
    }
}

From source file:co.thehotnews.lambda.TheHotNewsSpeechlet.java

License:Open Source License

private SpeechletResponse getCurrentStatus(String name, String screenName) {
    List<Status> statuses = null;
    try {//  www .  j  ava 2 s. c  om
        Twitter twitter = twitterFactory.getInstance();
        statuses = twitter.getUserTimeline(screenName);

    } catch (Exception e) {
        log.error("Problem getting current status for " + screenName, e);
        return getErrorResponse();
    }

    Status status = statuses.get(0);

    String statusText = ResponseUtils.removeUrl(status.getText());
    if (statusText == null || statusText.trim().length() == 0) {
        // assume there was only a link in the tweet.
        statusText = " a link. ";
    }

    String verb = status.isRetweet() ? " retweeted: " : " tweeted: ";
    String speechText = name + verb + statusText;
    String cardText = name + verb + status.getText();
    String mediaURl = null;
    if (status.getMediaEntities() != null && status.getMediaEntities().length > 0) {
        mediaURl = status.getMediaEntities()[0].getMediaURLHttps();
    }

    StandardCard card = new StandardCard();
    card.setTitle(APP_NAME);
    card.setText(cardText);
    if (mediaURl != null) {
        Image image = new Image();
        image.setLargeImageUrl(mediaURl);
        card.setImage(image);
    }

    // Create the plain text output.
    PlainTextOutputSpeech speech = new PlainTextOutputSpeech();
    speech.setText(speechText);

    return SpeechletResponse.newTellResponse(speech, card);
}