Example usage for twitter4j Status getCreatedAt

List of usage examples for twitter4j Status getCreatedAt

Introduction

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

Prototype

Date getCreatedAt();

Source Link

Document

Return the created_at

Usage

From source file:com.dwdesign.tweetings.model.ParcelableStatus.java

License:Open Source License

public ParcelableStatus(Status status, final long account_id, final boolean is_gap,
        final boolean large_inline_image_preview) {

    this.is_gap = is_gap;
    this.account_id = account_id;
    status_id = status.getId();/*  w w  w. jav  a 2 s  . co  m*/
    is_retweet = status.isRetweet();
    final Status retweeted_status = is_retweet ? status.getRetweetedStatus() : null;
    final User retweet_user = retweeted_status != null ? status.getUser() : null;
    retweet_id = retweeted_status != null ? retweeted_status.getId() : -1;
    retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1;
    retweeted_by_name = retweet_user != null ? retweet_user.getName() : null;
    retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null;
    if (retweeted_status != null) {
        status = retweeted_status;
    }
    final User user = status.getUser();
    user_id = user != null ? user.getId() : -1;
    name = user != null ? user.getName() : null;
    screen_name = user != null ? user.getScreenName() : null;
    profile_image_url = user != null ? user.getProfileImageURL() : null;
    profile_image_url_string = profile_image_url != null ? profile_image_url.toString() : null;
    is_protected = user != null ? user.isProtected() : false;
    is_verified = user != null ? user.isVerified() : false;
    final MediaEntity[] medias = status.getMediaEntities();

    status_timestamp = getTime(status.getCreatedAt());
    text_html = formatStatusText(status);
    final PreviewImage preview = getPreviewImage(text_html,
            large_inline_image_preview ? INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE_HIGH
                    : INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_SMALL);
    text_plain = status.getText();
    retweet_count = status.getRetweetCount();
    in_reply_to_screen_name = status.getInReplyToScreenName();
    in_reply_to_status_id = status.getInReplyToStatusId();
    source = status.getSource();
    location = new ParcelableLocation(status.getGeoLocation());
    location_string = location.toString();
    is_favorite = status.isFavorited();
    has_media = medias != null && medias.length > 0 || preview.has_image;
    text = text_html != null ? Html.fromHtml(text_html) : null;
    image_preview_url_string = preview.matched_url;
    image_orig_url_string = preview.orig_url;
    image_preview_url = parseURL(image_preview_url_string);
    text_unescaped = unescape(text_html);
    String play = null;
    URLEntity[] urls = status.getURLEntities();
    if (urls != null) {
        for (final URLEntity url : urls) {
            final URL tco_url = url.getURL();
            final URL expanded_url = url.getExpandedURL();
            if (tco_url != null && expanded_url != null
                    && expanded_url.toString().contains("play.google.com/store/apps")) {
                play = expanded_url.toString();
                break;
            }

        }
    }
    play_package = play;
    is_possibly_sensitive = status.isPossiblySensitive();
}

From source file:com.dwdesign.tweetings.util.Utils.java

License:Open Source License

public static ContentValues makeStatusContentValues(Status status, final long account_id) {
    if (status == null || status.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    values.put(Statuses.ACCOUNT_ID, account_id);
    values.put(Statuses.STATUS_ID, status.getId());
    final boolean is_retweet = status.isRetweet();
    final Status retweeted_status = is_retweet ? status.getRetweetedStatus() : null;
    if (retweeted_status != null) {
        final User retweet_user = status.getUser();
        values.put(Statuses.RETWEET_ID, retweeted_status.getId());
        values.put(Statuses.RETWEETED_BY_ID, retweet_user.getId());
        values.put(Statuses.RETWEETED_BY_NAME, retweet_user.getName());
        values.put(Statuses.RETWEETED_BY_SCREEN_NAME, retweet_user.getScreenName());
        status = retweeted_status;/*from  ww w  .j  a v  a  2 s .  co m*/
    }
    final User user = status.getUser();
    if (user != null) {
        final long user_id = user.getId();
        final String profile_image_url = user.getProfileImageURL().toString();
        final String name = user.getName(), screen_name = user.getScreenName();
        values.put(Statuses.USER_ID, user_id);
        values.put(Statuses.NAME, name);
        values.put(Statuses.SCREEN_NAME, screen_name);
        values.put(Statuses.IS_PROTECTED, user.isProtected() ? 1 : 0);
        values.put(Statuses.IS_VERIFIED, user.isVerified() ? 1 : 0);
        values.put(Statuses.PROFILE_IMAGE_URL, profile_image_url);
    }
    if (status.getCreatedAt() != null) {
        values.put(Statuses.STATUS_TIMESTAMP, status.getCreatedAt().getTime());
    }
    values.put(Statuses.TEXT, formatStatusText(status));
    values.put(Statuses.TEXT_PLAIN, status.getText());
    values.put(Statuses.RETWEET_COUNT, status.getRetweetCount());
    values.put(Statuses.IN_REPLY_TO_SCREEN_NAME, status.getInReplyToScreenName());
    values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
    values.put(Statuses.SOURCE, status.getSource());
    values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive());
    final GeoLocation location = status.getGeoLocation();
    if (location != null) {
        values.put(Statuses.LOCATION, location.getLatitude() + "," + location.getLongitude());
    }
    values.put(Statuses.IS_RETWEET, is_retweet ? 1 : 0);
    values.put(Statuses.IS_FAVORITE, status.isFavorited() ? 1 : 0);
    return values;
}

From source file:com.ebay.pulsar.twittersample.channel.TwitterSampleChannel.java

License:GNU General Public License

@Override
public void open() throws EventException {
    super.open();
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(false);//from   w  w  w  .  ja  v a 2 s.c  om

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    StatusListener listener = new StatusListener() {
        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
        }

        @Override
        public void onStallWarning(StallWarning warning) {
        }

        @Override
        public void onStatus(Status status) {
            HashtagEntity[] hashtagEntities = status.getHashtagEntities();

            JetstreamEvent event = new JetstreamEvent();
            event.setEventType("TwitterSample");

            Place place = status.getPlace();
            if (place != null) {
                event.put("country", place.getCountry());
            }
            event.put("ct", status.getCreatedAt().getTime());
            event.put("text", status.getText());
            event.put("lang", status.getLang());
            event.put("user", status.getUser().getName());
            if (hashtagEntities != null && hashtagEntities.length > 0) {
                StringBuilder s = new StringBuilder();
                s.append(hashtagEntities[0].getText());

                for (int i = 1; i < hashtagEntities.length; i++) {
                    s.append(",");
                    s.append(hashtagEntities[i].getText());
                }

                event.put("hashtag", s.toString());
            }

            fireSendEvent(event);
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }
    };
    twitterStream.addListener(listener);
    twitterStream.sample();
}

From source file:com.eventattend.portal.bl.TwitterBL.java

License:Open Source License

public List tweets(Twitter twitter, String screenName, TwitterDTO twitterDTO) throws BaseAppException {
    List tweetList = new ArrayList();

    List<Status> statuses = null;

    Paging paging = new Paging(1, 10);

    try {/*from w w  w  . j  ava 2 s .c o m*/
        statuses = twitter.getUserTimeline(screenName, paging);
    } catch (TwitterException e) {
        processTwitterException(e);
    }
    int i = 1;
    if (!statuses.isEmpty()) {

        for (Status status : statuses) {
            if (i <= 10) {
                User user = status.getUser();
                twitterDTO = new TwitterDTO();
                //   
                //   if(userId==status.getUser().getId()){
                if (status.getId() != 0) {
                    System.out.println(i + "TweetId=> " + status.getId());
                    twitterDTO.setTweetId(String.valueOf(status.getId()));
                }
                if (user.getProfileImageURL() != null) {
                    twitterDTO.setUserImg(user.getProfileImageURL().toString());
                }
                if (user.getScreenName() != null) {
                    twitterDTO.setUserScreeName("http://twitter.com/" + user.getScreenName());
                }
                if (user.getName() != null) {
                    twitterDTO.setUserName(user.getName());
                }
                if (status.getText() != null) {
                    twitterDTO.setTweet(status.getText());
                }
                System.out.println(status.getId() + " : " + status.getCreatedAt() + " >> " + status.getText());
                tweetList.add(twitterDTO);
                i++;
            } else {
                break;
            }

        }

    }

    return tweetList;
}

From source file:com.example.leonid.twitterreader.Twitter.TwitterGetTweets.java

License:Apache License

@Override
protected List<CreateTweet> doInBackground(String... params) {
    mTweetsInfo = new ArrayList<>();
    List<String> texts = new ArrayList<>();
    List<String> titles = new ArrayList<>();
    List<String> images = new ArrayList<>();
    List<String> date = new ArrayList<>();
    if (!isCancelled()) {
        ConfigurationBuilder cb = new ConfigurationBuilder();
        cb.setDebugEnabled(true).setOAuthConsumerKey(CONSUMER_KEY).setOAuthConsumerSecret(CONSUMER_SECRET)
                .setOAuthAccessToken(ACCESS_KEY).setOAuthAccessTokenSecret(ACCESS_SECRET);
        TwitterFactory tf = new TwitterFactory(cb.build());
        Twitter twitter = tf.getInstance();
        //query search result
        Query query = new Query(params[0]);
        //how much tweets need to be displayed(max 200)
        query.count(200);//w ww.ja v  a  2s .c om
        try {
            mResult = twitter.search(query);
            for (twitter4j.Status status : mResult.getTweets()) {
                if (!isCancelled()) {
                    texts.add(status.getText());
                    titles.add(status.getUser().getName());
                    images.add(status.getUser().getBiggerProfileImageURL());
                    String cleanDate = status.getCreatedAt().toString();
                    date.add(cleanDate.substring(0, cleanDate.length() - 15) + " "
                            + cleanDate.substring(cleanDate.length() - 4));
                }
            }
        } catch (TwitterException e) {
            Log.e("exeption", e.toString());
        }
        //loop teuth results and create array list for list view
        for (int i = 0; i < texts.size(); i++) {
            mTweetsInfo.add(new CreateTweet(titles.get(i), images.get(i), texts.get(i), date.get(i)));
        }

    }
    return mTweetsInfo;
}

From source file:com.finders.twitter.commands.TwitterRunnerOffline.java

License:Apache License

/**
 * Feed events from the stream to the engine
 * @param ksession//from w w w. ja  v a  2  s.  co m
 * @param ep
 */
private void feedEvents(final KieSession ksession, final EntryPoint ep) {
    try {
        StatusListener listener = new TwitterStatusListener(ep);
        ObjectInputStream in = new ObjectInputStream(getClass().getResourceAsStream("/twitterstream.dump"));
        SessionPseudoClock clock = ksession.getSessionClock();

        for (int i = 0;; i++) {
            try {
                // Read an event
                Status st = (Status) in.readObject();
                // Using the pseudo clock, advance the clock
                clock.advanceTime(st.getCreatedAt().getTime() - clock.getCurrentTime(), TimeUnit.MILLISECONDS);
                // call the listener
                listener.onStatus(st);
                if (this.dumpListener != null) {
                    this.dumpListener.onStatus(st);
                }
                ksession.getEntryPoint("twitter").insert(st);
            } catch (IOException ioe) {
                break;
            }
        }
        in.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:com.firewallid.commentwrapper.TwitterComment.java

public Map<String, String> formatOutput(Tuple3<Status, Status, Integer> statusComment, Status statusBase) {
    Status statusChild = statusComment._1();
    Status statusParent = statusComment._2();

    Map<String, String> comment = new HashMap<>();
    comment.put("id", String.valueOf(statusChild.getId()));
    comment.put("text", statusChild.getText());
    comment.put("userId", String.valueOf(statusChild.getUser().getId()));
    comment.put("userName", statusChild.getUser().getName());
    comment.put("userScreenName", statusChild.getUser().getScreenName());
    comment.put("time", String.valueOf(statusChild.getCreatedAt().getTime()));
    comment.put("replytoId", String.valueOf(statusParent.getId()));
    comment.put("replytoUserId", String.valueOf(statusParent.getUser().getId()));
    comment.put("replytoUserScreenName", statusParent.getUser().getScreenName());
    comment.put("depth", String.valueOf(statusComment._3()));
    comment.put("baseId", String.valueOf(statusBase.getId()));
    comment.put("baseUserId", String.valueOf(statusBase.getUser().getId()));
    comment.put("baseUserScreenName", statusBase.getUser().getScreenName());

    LOG.info(Joiner.on(". ").withKeyValueSeparator(":").join(comment));

    return comment;
}

From source file:com.firewallid.crawling.TwitterApp.java

public List<Status> replyTo(Status status) {
    String userScreenName = status.getUser().getScreenName();
    String date = new SimpleDateFormat("YYYY-MM-DD").format(status.getCreatedAt());
    Query query = new Query("to:" + userScreenName + " since:" + date);
    List<Status> repliesAll = new ArrayList<>();

    while (query != null) {
        QueryResult result = search(query);

        List<Status> replies = result.getTweets().parallelStream()
                /* Only reply to status's id*/
                .filter(tweet -> tweet.getInReplyToStatusId() == status.getId()).collect(Collectors.toList());

        repliesAll.addAll(replies);// w  ww  .j a  v  a  2s. c o m
        query = result.nextQuery();
    }

    return repliesAll;
}

From source file:com.firewallid.crawling.TwitterStreaming.java

public JavaPairDStream<String, Map<String, String>> streaming(JavaStreamingContext jsc) {
    /* Twitter Application */
    System.setProperty("twitter4j.oauth.consumerKey", conf.get(CONSUMER_KEY));
    System.setProperty("twitter4j.oauth.consumerSecret", conf.get(CONSUMER_SECRET));
    System.setProperty("twitter4j.oauth.accessToken", conf.get(ACCESS_TOKEN));
    System.setProperty("twitter4j.oauth.accessTokenSecret", conf.get(ACCESS_TOKEN_SECRET));

    JavaPairDStream<String, Map<String, String>> crawl = TwitterUtils
            /* Streaming */
            .createStream(jsc)//w ww . j  av  a2 s.co  m
            /* Indonesia language filtering */
            .filter((Status status) -> idLanguageDetector.detect(status.getText()))
            /* Collect data */
            .mapToPair((Status status) -> {
                Map<String, String> columns = new HashMap<>();
                columns.put("text", status.getText());
                columns.put("date", String.valueOf(status.getCreatedAt().getTime()));
                columns.put("screenName", status.getUser().getScreenName());
                columns.put("userName", status.getUser().getName());
                columns.put("userId", String.valueOf(status.getUser().getId()));

                LOG.info(String.format("id: %s. %s", status.getId(),
                        Joiner.on(". ").withKeyValueSeparator(": ").join(columns)));

                return new Tuple2<String, Map<String, String>>(String.valueOf(status.getId()), columns);
            });

    return crawl;
}

From source file:com.freshdigitable.udonroad.module.realm.StatusRealm.java

License:Apache License

StatusRealm(Status status) {
    this.id = status.getId();
    this.createdAt = status.getCreatedAt();
    this.retweetedStatus = status.getRetweetedStatus();
    this.retweet = status.isRetweet();
    if (status.isRetweet()) {
        this.retweetedStatusId = this.retweetedStatus.getId();
    }/*w  w  w.  j a v a2 s . c  o  m*/
    this.text = status.getText();
    this.source = status.getSource();
    this.retweetCount = status.getRetweetCount();
    this.favoriteCount = status.getFavoriteCount();
    this.reaction = new StatusReactionImpl(status);
    this.user = status.getUser();
    this.userId = user.getId();
    this.urlEntities = URLEntityRealm.createList(status.getURLEntities());

    this.mediaEntities = new RealmList<>();
    final ExtendedMediaEntity[] me = status.getExtendedMediaEntities();
    for (ExtendedMediaEntity m : me) {
        mediaEntities.add(new ExtendedMediaEntityRealm(m));
    }
    final UserMentionEntity[] userMentionEntities = status.getUserMentionEntities();
    this.userMentionEntities = new RealmList<>();
    for (UserMentionEntity u : userMentionEntities) {
        this.userMentionEntities.add(new UserMentionEntityRealm(u));
    }

    this.quotedStatus = status.getQuotedStatus();
    this.quotedStatusId = status.getQuotedStatusId();
}