List of usage examples for twitter4j Status getText
String getText();
From source file:com.dhamacher.sentimentanalysis4tweets.common.LocalTweet.java
License:Apache License
public void copyFrom(Status tweet) { setId(tweet.getId());/*from ww w .jav 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// w w w . j av a 2s . c o m * @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.sentimentanalysis4tweets.sentiment.Tokenizer.java
License:Apache License
/** * Retrieve the tokens in a Tweet. These are returned as a linked list of * strings; each string is a token, and they are ordered as they occur in * the tweet.//from w w w . j a va 2 s .c o m * * Before the tokenization occurs, some preprocessing is performed on the * string, to properly convert URL's. * * @param tweet The tweet to tokenize. * @return The tokens in the tweets text. */ public LinkedList<String> getTokens(Status tweet) throws IOException { String text = TextNormalizer.getTweetWithoutUrlsAnnotations(tweet.getText()); return getTokens(text); }
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();//from w w w . j a v a2s. c om 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 va 2s .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 String formatStatusText(final Status status) { if (status == null) return null; final String text = status.getText(); if (text == null) return null; final HtmlBuilder builder = new HtmlBuilder(text, false); parseEntities(builder, status);//from ww w. j a v a 2 s .c o m return builder.build(true); }
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;// w w w. j a v a 2 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 ww . j ava 2 s. c om*/ }
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 w w . ja va 2s . com*/ 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);/*from www . j av a2 s. 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(); }