List of usage examples for twitter4j Status getUser
User getUser();
From source file:com.daiv.android.twitter.data.sq_lite.MentionsDataSource.java
License:Apache License
public synchronized int insertTweets(List<Status> statuses, int account) { ContentValues[] valueses = new ContentValues[statuses.size()]; for (int i = 0; i < statuses.size(); i++) { Status status = statuses.get(i); ContentValues values = new ContentValues(); String originalName = ""; long id = status.getId(); long time = status.getCreatedAt().getTime(); String[] html = TweetLinkUtils.getLinksInStatus(status); String text = html[0];/*www .j a v a 2 s . co m*/ String media = html[1]; String otherUrl = html[2]; String hashtags = html[3]; String users = html[4]; if (media.contains("/tweet_video/")) { media = media.replace("tweet_video", "tweet_video_thumb").replace(".mp4", ".png"); } values.put(MentionsSQLiteHelper.COLUMN_ACCOUNT, account); values.put(MentionsSQLiteHelper.COLUMN_TEXT, text); values.put(MentionsSQLiteHelper.COLUMN_TWEET_ID, id); values.put(MentionsSQLiteHelper.COLUMN_NAME, status.getUser().getName()); values.put(MentionsSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL()); values.put(MentionsSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName()); values.put(MentionsSQLiteHelper.COLUMN_TIME, time); values.put(MentionsSQLiteHelper.COLUMN_RETWEETER, originalName); values.put(MentionsSQLiteHelper.COLUMN_UNREAD, 1); values.put(MentionsSQLiteHelper.COLUMN_PIC_URL, media); values.put(MentionsSQLiteHelper.COLUMN_URL, otherUrl); values.put(MentionsSQLiteHelper.COLUMN_USERS, users); values.put(MentionsSQLiteHelper.COLUMN_HASHTAGS, hashtags); values.put(MentionsSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, otherUrl)); values.put(HomeSQLiteHelper.COLUMN_CONVERSATION, status.getInReplyToStatusId() == -1 ? 0 : 1); valueses[i] = values; } return insertMultiple(valueses); }
From source file:com.daiv.android.twitter.utils.TweetLinkUtils.java
License:Apache License
public static String getGIFUrl(Status s, String otherUrls) { // this will be used after twitter begins to support them for (ExtendedMediaEntity e : s.getExtendedMediaEntities()) { if (e.getType().equals("animated_gif")) { return e.getMediaURL().replace("tweet_video_thumb", "tweet_video").replace(".png", ".mp4"); } else if (e.getType().equals("video")) { if (e.getVideoVariants().length > 0) { String url = ""; for (ExtendedMediaEntity.Variant v : e.getVideoVariants()) { if (v.getUrl().contains(".mp4")) { url = v.getUrl(); }/* w w w . j a va2 s . c o m*/ } Log.v("Test_video_link", url); return url; } } } // this is how the urls are currently stored String gifUrl = "twitter.com/" + s.getUser().getScreenName() + "/status/" + s.getId() + "/photo/1"; if (otherUrls.contains(gifUrl)) { return gifUrl; } // otherwise, lets just go with a blank string return ""; }
From source file:com.dhamacher.sentimentanalysis4tweets.common.LocalTweet.java
License:Apache License
public void copyFrom(Status tweet) { setId(tweet.getId());/*from w w w . ja v a 2s . co m*/ setContent(tweet.getText()); setAuthor(tweet.getUser().getName()); setDate(tweet.getCreatedAt()); setAuthorId(tweet.getId()); fromDB = false; }
From source file:com.dhamacher.sentimentanalysis4tweets.database.Operator.java
License:Apache License
/** * Stores tweets inside the database//from w w w. j a v a2 s .com * @param tw The tweet to save */ @Override public void storeTweet(Status tw) { /* Extract the date of the tweet in a certain format */ Date date = (Date) tw.getCreatedAt(); java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String currentTime = sdf.format(date); //Pagerank pgtw = new Pagerank(author); try { /* Prepare query to execute to the database */ String query = "INSERT INTO tweets(id, content, author, date) VALUES(?,?,?,?)"; PreparedStatement stmt = (PreparedStatement) con.getCon().prepareStatement(query); stmt.clearParameters(); /* Set the record attribuuttes using the values from the tweet instance */ stmt.setLong(1, tw.getId()); stmt.setString(2, tw.getText().replaceAll("'", "")); stmt.setString(3, tw.getUser().getName()); stmt.setString(4, currentTime); stmt.addBatch(); /* Execute query */ stmt.executeUpdate(); } catch (SQLException ex) { Logger.getLogger(Operator.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.dhamacher.tweetsentimentanalysis.Main.java
License:Open Source License
private static void persistTweet(QueryResult result, String token) { EntityTransaction tx = em.getTransaction(); tx.begin();//w w w . ja v a2s. com for (Status status : result.getTweets()) { Tweet entity = new Tweet(); entity.setTweetId(status.getId()); entity.setSearchToken(token); entity.setCreatedOn(status.getCreatedAt()); entity.setIsRetweet(status.isRetweet()); entity.setSource(status.getSource()); entity.setUser(status.getUser()); entity.setText(status.getText()); em.persist(entity); } tx.commit(); }
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();/*from w w w . ja va2 s . com*/ 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 w w w.j a v a2 s .c om } 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.e2.StreamingListener.java
public void onStatus(Status status) { System.out.println(status.getUser().getName() + " : " + status.getText()); if (status.getText().startsWith("@oic___bot")) { System.out.println("Replay ::::::::::::::::" + status.getText()); }/*from w w w.j a v a2 s.c o m*/ }
From source file:com.e2.UserStreamListener.java
public void onStatus(Status status) { System.out.println(status.getUser().getName() + " : " + status.getText()); if (status.getText().startsWith("@e2_oic")) { try {/* w ww . j ava 2s .co m*/ String text = status.getText().replaceAll("@e2_oic ", ""); //System.out.println(text); MessageSender.send(text); } catch (Exception e) { } } }
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);/* w w w .j av a 2s . c o m*/ 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(); }