Example usage for twitter4j Status isRetweetedByMe

List of usage examples for twitter4j Status isRetweetedByMe

Introduction

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

Prototype

boolean isRetweetedByMe();

Source Link

Document

Returns true if the authenticating user has retweeted this tweet, or false when the tweet was created before this feature was enabled.

Usage

From source file:nl.isaac.dotcms.twitter.pojo.CustomStatus.java

License:Creative Commons License

public CustomStatus(Status status) {
    this.createdAt = status.getCreatedAt();
    this.id = status.getId();
    this.id_str = String.valueOf(status.getId());
    this.text = status.getText();
    this.source = status.getSource();
    this.isTruncated = status.isTruncated();
    this.inReplyToStatusId = status.getInReplyToStatusId();
    this.inReplyToUserId = status.getInReplyToUserId();
    this.isFavorited = status.isFavorited();
    this.inReplyToScreenName = status.getInReplyToScreenName();
    this.geoLocation = status.getGeoLocation();
    this.place = status.getPlace();
    this.retweetCount = status.getRetweetCount();
    this.isPossiblySensitive = status.isPossiblySensitive();

    this.contributorsIDs = status.getContributors();

    this.retweetedStatus = status.getRetweetedStatus();
    this.userMentionEntities = status.getUserMentionEntities();
    this.urlEntities = status.getURLEntities();
    this.hashtagEntities = status.getHashtagEntities();
    this.mediaEntities = status.getMediaEntities();
    this.currentUserRetweetId = status.getCurrentUserRetweetId();

    this.isRetweet = status.isRetweet();
    this.isRetweetedByMe = status.isRetweetedByMe();

    this.rateLimitStatus = status.getRateLimitStatus();
    this.accessLevel = status.getAccessLevel();
    this.user = status.getUser();
}

From source file:org.botlibre.sense.twitter.Twitter.java

License:Open Source License

/**
 * Check status./*  w ww .j av a2 s  .  co  m*/
 */
public void checkStatus() {
    if (!getProcessStatus()) {
        return;
    }
    log("Checking status", Level.FINE);
    try {
        Network memory = getBot().memory().newMemory();
        Vertex twitter = memory.createVertex(getPrimitive());
        Vertex vertex = twitter.getRelationship(Primitive.LASTTIMELINE);
        long last = 0;
        if (vertex != null) {
            last = ((Number) vertex.getData()).longValue();
        }
        long max = 0;
        ResponseList<Status> timeline = null;
        boolean more = true;
        int page = 1;
        int count = 0;
        this.errors = 0;
        while (more && (count <= this.maxStatus) && page <= this.maxPage) {
            if (last == 0) {
                timeline = getConnection().getHomeTimeline();
                more = false;
            } else {
                Paging paging = new Paging(page, last);
                timeline = getConnection().getHomeTimeline(paging);
                if ((timeline == null) || (timeline.size() < 20)) {
                    more = false;
                }
                page++;
            }
            if ((timeline == null) || timeline.isEmpty()) {
                break;
            }
            log("Processing status", Level.INFO, timeline.size());
            for (int index = timeline.size() - 1; index >= 0; index--) {
                if (count >= this.maxStatus) {
                    break;
                }
                if (this.errors > this.maxErrors) {
                    break;
                }
                Status status = timeline.get(index);
                String name = status.getUser().getScreenName();
                if (!name.equals(this.userName)) {
                    long statusTime = status.getCreatedAt().getTime();
                    long statusId = status.getId();
                    if (statusId > max) {
                        max = statusId;
                    }
                    if ((System.currentTimeMillis() - statusTime) > DAY) {
                        log("Day old status", Level.INFO, statusId, statusTime);
                        more = false;
                        continue;
                    }
                    if (statusId > last) {
                        if (Utils.checkProfanity(status.getText())) {
                            continue;
                        }
                        boolean match = false;
                        List<String> statusWords = new TextStream(status.getText().toLowerCase()).allWords();
                        if (getListenStatus()) {
                            this.languageState = LanguageState.Listening;
                            match = true;
                        } else {
                            for (String text : getStatusKeywords()) {
                                List<String> keywords = new TextStream(text.toLowerCase()).allWords();
                                if (!keywords.isEmpty() && statusWords.containsAll(keywords)) {
                                    match = true;
                                    break;
                                }
                            }
                        }
                        if (getLearn()) {
                            learnTweet(status, true, true, memory);
                        }
                        if (match) {
                            count++;
                            input(status);
                            Utils.sleep(500);
                        } else {
                            log("Skipping status, missing keywords", Level.FINE, status.getText());
                            if (!status.isRetweet() && !status.getUser().isProtected()
                                    && !status.isRetweetedByMe()) {
                                boolean retweeted = false;
                                // Check retweet.
                                for (String keywords : getRetweet()) {
                                    List<String> keyWords = new TextStream(keywords.toLowerCase()).allWords();
                                    if (!keyWords.isEmpty()) {
                                        if (statusWords.containsAll(keyWords)) {
                                            retweeted = true;
                                            count++;
                                            retweet(status);
                                            Utils.sleep(500);
                                            break;
                                        }
                                    }
                                }
                                if (!retweeted) {
                                    log("Skipping rewteet, missing keywords", Level.FINE, status.getText());
                                }
                            } else if (!getRetweet().isEmpty()) {
                                if (status.isRetweet()) {
                                    log("Skipping rewteet", Level.FINE, status.getText());
                                } else if (status.getUser().isProtected()) {
                                    log("Skipping protected user", Level.FINE, status.getText());
                                } else if (status.isRetweetedByMe()) {
                                    log("Skipping already retweeted", Level.FINE, status.getText());
                                }
                            }
                        }
                    } else {
                        log("Old status", Level.INFO, statusId, statusTime);
                    }
                }
            }
        }
        if (max != 0) {
            twitter.setRelationship(Primitive.LASTTIMELINE, memory.createVertex(max));
            memory.save();
        }
    } catch (Exception exception) {
        log(exception);
    }
    // Wait for language processing.
    int count = 0;
    while (count < 60 && !getBot().memory().getActiveMemory().isEmpty()) {
        Utils.sleep(1000);
    }
}

From source file:org.botlibre.sense.twitter.Twitter.java

License:Open Source License

/**
 * Check search keywords./*from  ww  w  .  java 2 s. c  o  m*/
 */
public void checkSearch() {
    if (getTweetSearch().isEmpty()) {
        return;
    }
    log("Processing search", Level.FINE, getTweetSearch());
    try {
        Network memory = getBot().memory().newMemory();
        Vertex twitter = memory.createVertex(getPrimitive());
        Vertex vertex = twitter.getRelationship(Primitive.LASTSEARCH);
        long last = 0;
        long max = 0;
        int count = 0;
        this.errors = 0;
        if (vertex != null) {
            last = ((Number) vertex.getData()).longValue();
        }
        Set<Long> processed = new HashSet<Long>();
        for (String tweetSearch : getTweetSearch()) {
            Query query = new Query(tweetSearch);
            if (vertex != null) {
                query.setSinceId(last);
            }
            SearchResource search = getConnection().search();
            QueryResult result = search.search(query);
            List<Status> tweets = result.getTweets();
            if (tweets != null) {
                log("Processing search results", Level.FINE, tweets.size(), tweetSearch);
                for (Status tweet : tweets) {
                    if (count > this.maxSearch) {
                        log("Max search results processed", Level.FINE, this.maxSearch);
                        break;
                    }
                    if (tweet.getId() > last && !processed.contains(tweet.getId())) {
                        if (tweet.getId() > max) {
                            max = tweet.getId();
                        }
                        boolean match = false;
                        // Exclude replies/mentions
                        if (getIgnoreReplies() && tweet.getText().indexOf('@') != -1) {
                            log("Ignoring: Tweet is reply", Level.FINER, tweet.getText());
                            continue;
                        }
                        // Exclude retweets
                        if (tweet.isRetweet()) {
                            log("Ignoring: Tweet is retweet", Level.FINER, tweet.getText());
                            continue;
                        }
                        // Exclude protected
                        if (tweet.getUser().isProtected()) {
                            log("Ignoring: Tweet is protected", Level.FINER, tweet.getText());
                            continue;
                        }
                        // Exclude self
                        if (tweet.getUser().getScreenName().equals(getUserName())) {
                            log("Ignoring: Tweet is from myself", Level.FINER, tweet.getText());
                            continue;
                        }
                        // Ignore profanity
                        if (Utils.checkProfanity(tweet.getText())) {
                            log("Ignoring: Tweet contains profanity", Level.FINER, tweet.getText());
                            continue;
                        }
                        List<String> statusWords = new TextStream(tweet.getText().toLowerCase()).allWords();
                        for (String text : getStatusKeywords()) {
                            List<String> keywords = new TextStream(text.toLowerCase()).allWords();
                            if (statusWords.containsAll(keywords)) {
                                match = true;
                                break;
                            }
                        }
                        if (getLearn()) {
                            learnTweet(tweet, true, true, memory);
                        }
                        if (match) {
                            processed.add(tweet.getId());
                            log("Processing search", Level.INFO, tweet.getUser().getScreenName(), tweetSearch,
                                    tweet.getText());
                            input(tweet);
                            Utils.sleep(500);
                            count++;
                        } else {
                            if (!tweet.isRetweetedByMe()) {
                                boolean found = false;
                                // Check retweet.
                                for (String keywords : getRetweet()) {
                                    List<String> keyWords = new TextStream(keywords).allWords();
                                    if (!keyWords.isEmpty()) {
                                        if (statusWords.containsAll(keyWords)) {
                                            found = true;
                                            processed.add(tweet.getId());
                                            count++;
                                            retweet(tweet);
                                            Utils.sleep(500);
                                            break;
                                        }
                                    }
                                }
                                if (!found) {
                                    log("Missing keywords", Level.FINER, tweet.getText());
                                }
                            } else {
                                log("Already retweeted", Level.FINER, tweet.getText());
                            }
                        }
                    }
                }
            }
            if (count > this.maxSearch) {
                break;
            }
            if (this.errors > this.maxErrors) {
                break;
            }
        }
        if (max != 0) {
            twitter.setRelationship(Primitive.LASTSEARCH, memory.createVertex(max));
            memory.save();
        }
    } catch (Exception exception) {
        log(exception);
    }
    // Wait for language processing.
    int count = 0;
    while (count < 60 && !getBot().memory().getActiveMemory().isEmpty()) {
        Utils.sleep(1000);
    }
}

From source file:org.examproject.tweet.service.SimpleTweetService.java

License:Apache License

private TweetDto mapStatus(Status status) {
    TweetDto tweetDto = new TweetDto();
    tweetDto.setUserProfileImageURL(status.getUser().getProfileImageURL().toString());
    tweetDto.setUserName(status.getUser().getScreenName());
    tweetDto.setText(status.getText());/*from   w w w  .j  a  v a 2 s.c o m*/
    tweetDto.setStatusId(String.valueOf(status.getId()));
    tweetDto.setCreated(status.getCreatedAt());
    tweetDto.setIsFavorited(status.isFavorited());
    tweetDto.setIsRetweetedByMe(status.isRetweetedByMe());
    return tweetDto;
}

From source file:org.tweetalib.android.model.TwitterStatus.java

License:Apache License

public TwitterStatus(Status status) {
    User statusUser = status.getUser();/*w  w  w.  j a v a2  s.c  o m*/

    mCreatedAt = status.getCreatedAt();
    mId = status.getId();
    if (status.getInReplyToStatusId() != -1) {
        mInReplyToStatusId = status.getInReplyToStatusId();
    }
    if (status.getInReplyToUserId() != -1) {
        mInReplyToUserId = status.getInReplyToUserId();
    }
    mInReplyToUserScreenName = status.getInReplyToScreenName();
    mIsFavorited = status.isFavorited();
    mIsRetweet = status.isRetweet();
    mIsRetweetedByMe = status.isRetweetedByMe();

    mSource = TwitterUtil.stripMarkup(status.getSource());

    if (statusUser != null) {
        mUserId = statusUser.getId();
        mUserName = statusUser.getName();
        mUserScreenName = statusUser.getScreenName();
    }

    mMediaEntity = TwitterMediaEntity.createMediaEntity(status);

    boolean useDefaultAuthor = true;
    if (mIsRetweet) {
        if (status.getRetweetedStatus() != null && status.getRetweetedStatus().getUser() != null) {
            SetProfileImagesFromUser(new TwitterUser(status.getRetweetedStatus().getUser()));
        }
        mOriginalRetweetId = status.getRetweetedStatus().getId();

        // You'd think this check wasn't necessary, but apparently not...
        UserMentionEntity[] userMentions = status.getUserMentionEntities();
        if (userMentions != null && userMentions.length > 0) {
            useDefaultAuthor = false;
            UserMentionEntity authorMentionEntity = status.getUserMentionEntities()[0];
            mAuthorId = authorMentionEntity.getId();
            mAuthorName = authorMentionEntity.getName();
            mAuthorScreenName = authorMentionEntity.getScreenName();

            Status retweetedStatus = status.getRetweetedStatus();
            mStatus = retweetedStatus.getText();
            setStatusMarkup(retweetedStatus);
            mRetweetCount = retweetedStatus.getRetweetCount();
            mUserMentions = TwitterUtil.getUserMentions(retweetedStatus.getUserMentionEntities());
            mIsRetweetedByMe = retweetedStatus.isRetweetedByMe();
        }
    } else {
        if (statusUser != null) {
            SetProfileImagesFromUser(new TwitterUser(statusUser));
        }
    }

    if (useDefaultAuthor) {
        if (statusUser != null) {
            mAuthorId = statusUser.getId();
        }
        mStatus = status.getText();
        setStatusMarkup(status);
        mRetweetCount = status.getRetweetCount();
        mUserMentions = TwitterUtil.getUserMentions(status.getUserMentionEntities());
    }

    /*
     * if (status.getId() == 171546910249852928L) { mStatus =
     * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?"
     * ; mStatusMarkup =
     * "<a href=\"http://a.com\">@chrismlacy</a> You've been working on Tweet Lanes for ages. Is it done yet?"
     * ; mAuthorScreenName = "emmarclarke"; mStatusMarkup = mStatus; } else
     * if (status.getId() == 171444098698457089L) { mStatus =
     * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?"
     * ; mStatusMarkup =
     * "<a href=\"http://a.com\">@chrismlacy</a> How's that app of yours coming along?"
     * ; mStatusMarkup = mStatus; }
     */
}

From source file:twitterbot.TwitterActions.java

public void searchTweetandRetweet(String hashtag) {
    Query query = new Query(hashtag);
    query.count(40);/*from ww w . j a  v a 2  s.c om*/
    int check = 0;
    int alreadyused = 0;
    int remove = 0;

    try {
        QueryResult queryresult = this.twitter.search(query);
        this.tweets = (ArrayList<Status>) queryresult.getTweets();
        Collections.reverse(tweets);
        for (Status status : tweets) {
            if (!status.isRetweetedByMe() && status.getCreatedAt().getTime() > this.lastStatusTime) {
                try {
                    this.retweetTweet(status);
                    this.lastStatusTime = status.getCreatedAt().getTime();
                    this.writeTimeToFile();
                    Thread.sleep(10000);
                } catch (TwitterException tex) {
                    System.out.println("Twitter Exception - Already Retweeted");
                }
            }
        }
    } catch (TwitterException ex) {
        Logger.getLogger(TwitterActions.class.getName()).log(Level.SEVERE, null, ex);

    } catch (InterruptedException ex) {
        Logger.getLogger(TwitterActions.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:twitterbot.TwitterActions.java

public void retweetAllTweetsFromTimeline() {
    try {//from  w  w  w  .  j av  a 2s.  c o  m
        this.tweets = (ArrayList<Status>) twitter.getHomeTimeline();
        Collections.reverse(tweets);

        for (Status status : tweets) {
            if (!status.isRetweetedByMe() && status.getCreatedAt().getTime() > this.lastStatusTime) {
                this.retweetTweet(status);
                this.lastStatusTime = status.getCreatedAt().getTime();
                this.writeTimeToFile();
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(TwitterActions.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    } catch (TwitterException ex) {
        Logger.getLogger(TwitterActions.class.getName()).log(Level.SEVERE, null, ex);
    }

}