List of usage examples for twitter4j Status getCreatedAt
Date getCreatedAt();
From source file:com.mycompany.omnomtweets.TweetsAboutCandidates.java
/** * Method to write the tweets to file, base 64 encoded tweet text. * @param tweets the tweets to be written * @param filename the file to write the tweets into * @return true unless something bad happens *//*from w w w. j a va2 s . c o m*/ public boolean writeTweetsToFile(List<Status> tweets, String filename) { //System.out.println("Writing " + tweets.size() + " tweets"); boolean success = true; try { FileWriter addTweets = new FileWriter(new File(filename), true); if (tweets != null && tweets.size() > 0) { for (Status tweet : tweets) { String tweetText; String idOfRetweetee = ""; if (tweet.getRetweetedStatus() != null) { tweetText = "RT " + tweet.getRetweetedStatus().getText(); idOfRetweetee = "" + tweet.getRetweetedStatus().getUser().getScreenName(); //System.out.println("retweeted" + tweetText); } else { tweetText = tweet.getText(); } String urlText = ""; if (tweet.getURLEntities().length > 0) { for (URLEntity url : tweet.getURLEntities()) { if (url.getExpandedURL() != null) { urlText += url.getExpandedURL() + " "; //System.out.println("Expanded URL " + url.getExpandedURL()); } else { urlText += url.getURL() + " "; //System.out.println("URL " + url.getURL()); } } } if (tweet.getMediaEntities().length > 0) { for (MediaEntity media : tweet.getMediaEntities()) { if (media.getExpandedURL() != null) { urlText += media.getExpandedURL() + " "; //System.out.println("Expanded URL " + media.getExpandedURL()); } else { urlText += media.getMediaURL() + " "; //System.out.println("URL " + media.getMediaURL()); } } } String encodedText = tweet.getText().replaceAll("\"", "\"\""); String writeMe = "\"" + encodedText + "\"," + urlText + "," + tweet.getUser().getId() + "," + tweet.getId() + "," + candidate.name + "," + tweet.getCreatedAt() + "," + idOfRetweetee + "\n"; //System.out.println(writeMe); addTweets.write(writeMe); } } addTweets.close(); } catch (IOException ex) { System.out.println("Something broke lol"); success = false; } return success; }
From source file:com.mycompany.twitterproductanalysistool.TwitterAPI.java
public ArrayList<String> getQuery(String qry) { tweets = new ArrayList<>(); tweetCountries = new ArrayList<>(); tweetDates = new ArrayList<>(); try {/*from ww w . j a v a2 s. co m*/ Query query = new Query(qry); query.setCount(99); result = twitter.search(query); for (Status status : result.getTweets()) { tweets.add(status.getText()); tweetDates.add(status.getCreatedAt()); if (status.getUser() == null) { tweetCountries.add("NO COUNTRY"); } else { tweetCountries.add(status.getUser().getLocation()); } } } catch (TwitterException te) { te.printStackTrace(); System.out.println("Failed to search tweets: " + te.getMessage()); System.exit(-1); } for (int i = 0; i < tweets.size(); i++) { String s = tweets.get(i); tweets.set(i, s.replace("\n", "")); } return tweets; }
From source file:com.ocpsoft.hatchling.twitter.PersistentStatusListener.java
License:Open Source License
@Override public void onStatus(final Status status) { Tweet t = new Tweet(); t.setReceived(status.getCreatedAt()); t.setText(status.getText());//w w w. j a v a 2s . com t.setScreenName(status.getUser().getScreenName()); t.setUserName(status.getUser().getName()); t.setUserProfileImageURL(status.getUser().getProfileImageURL()); t.setProfileURL(null); t.setTweetId(status.getId()); URLEntity[] urlEntities = status.getURLEntities(); if (urlEntities != null) { for (URLEntity url : urlEntities) { TweetURL tweetURL = new TweetURL(); if (url.getExpandedURL() != null) { tweetURL.setURL(url.getExpandedURL()); } else if (url.getURL() != null) { tweetURL.setURL(url.getURL()); } t.getURLs().add(tweetURL); } } buffer.add(t); }
From source file:com.projectlaver.util.TwitterListingResponseHandler.java
License:Open Source License
public void processStatus(Status status) { if (this.logger.isDebugEnabled()) { this.logger.debug("+processStatus() with status id: " + status.getId()); }//from ww w . j a va 2s . c o m String twitterId = this.longToString(status.getId()); User profile = status.getUser(); // Convert twitterIds to Strings here because these fields are treated as varchars by the database String providerUserId = this.longToString(profile.getId()); String inReplyToStatusId = this.longToString(status.getInReplyToStatusId()); String tweetText = status.getText(); Boolean isRetweet = (status.getRetweetedStatus() != null); // these two fields are required; without an @mention and a #hashtag we do not need to persist this tweet String mentionedProviderUserId = this.getMentionedProviderUserId(status.getUserMentionEntities()); String hashtag = this.getMentionedHashtag(status.getHashtagEntities()); if (StringUtils.isNoneBlank(mentionedProviderUserId, hashtag)) { ReplyMessageDTO dto = new ReplyMessageDTO(SocialProviders.TWITTER, providerUserId, twitterId, inReplyToStatusId, null, isRetweet, tweetText, hashtag, INITIAL_STATUS, status.getCreatedAt()); // Use a try catch here to trap excptions try { super.processUserMessage(mentionedProviderUserId, dto, false); // Retry on deadlock } catch (DeadlockLoserDataAccessException e) { this.logger.error("Lost deadlock trying to insert tweet. Falling back on retry logic."); this.retryProcessAfterDeadlock(mentionedProviderUserId, dto); // Log on uncaught exception } catch (Exception e) { this.logger.error(String.format( "Valid message with id: %s read by stream, but processing failed with an exception.", twitterId), e); this.logger.error("UNINSERTED TWEET: " + ToStringBuilder.reflectionToString(dto)); } } if (this.logger.isDebugEnabled()) { this.logger.debug("-processStatus() with status id: " + status.getId()); } }
From source file:com.pulzitinc.flume.source.TwitterSource.java
License:Apache License
/** * Start processing events. This uses the Twitter Streaming API to sample * Twitter, and process tweets.// w w w . java 2 s. c o m */ @Override public void start() { // The channel is the piece of Flume that sits between the Source and Sink, // and is used to process events. final ChannelProcessor channel = getChannelProcessor(); final Map<String, String> headers = new HashMap<String, String>(); // The StatusListener is a twitter4j API, which can be added to a Twitter // stream, and will execute methods every time a message comes in through // the stream. UserStreamListener listener = new UserStreamAdapter() { // The onStatus method is executed every time a new tweet comes in. public void onStatus(Status status) { // The EventBuilder is used to build an event using the headers and // the raw JSON of a tweet logger.debug(status.getUser().getScreenName() + ": " + status.getText() + " - " + TwitterObjectFactory.getRawJSON(status)); headers.put("timestamp", String.valueOf(status.getCreatedAt().getTime())); Event event = EventBuilder.withBody(DataObjectFactory.getRawJSON(status).getBytes(), headers); channel.processEvent(event); } public void onException(Exception ex) { ex.printStackTrace(); } }; logger.debug("Setting up Twitter stream using consumer key {} and access token {}", new String[] { consumerKey, accessToken }); // Set up the stream's listener (defined above), twitterStream.addListener(listener); logger.debug("Starting up Twitter consuming..."); twitterStream.user(); super.start(); }
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static Map getFieldsMapFromStatus(String queryOwner, String queryName, String queryString, Status status) { if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); Map m = StatusArraysHelper.getUserMentionMap(status); Map newMap = new HashMap(); for (Object key : m.keySet()) { newMap.put(key.toString(), (Long) m.get(key)); }/*from ww w . j a v a2 s.co m*/ Double longitude = null; Double lattitude = null; if (status.getGeoLocation() != null) { longitude = status.getGeoLocation().getLongitude(); lattitude = status.getGeoLocation().getLatitude(); } String place = null; if (status.getPlace() != null) { place = status.getPlace().getFullName(); } boolean isRetweet = status.getRetweetedStatus() != null; Long retweetedId = null; String retweetedText = null; if (isRetweet) { retweetedId = status.getRetweetedStatus().getId(); retweetedText = status.getRetweetedStatus().getText(); } Map<String, Object> result = new HashMap<>(); result.put(QueryResultItemFieldNames.STATUS_ID, status.getId()); result.put(QueryResultItemFieldNames.CREATED_AT, status.getCreatedAt()); result.put(QueryResultItemFieldNames.CURRENT_USER_RETWEET_ID, status.getCurrentUserRetweetId()); result.put(QueryResultItemFieldNames.FAVOURITE_COUNT, status.getFavoriteCount()); result.put(QueryResultItemFieldNames.FAVOURITED, status.isFavorited()); result.put(QueryResultItemFieldNames.HASHTAGS, StatusArraysHelper.getHashTagsList(status)); result.put(QueryResultItemFieldNames.IN_REPLY_TO_SCREEN_NAME, (status.getInReplyToScreenName())); result.put(QueryResultItemFieldNames.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId()); result.put(QueryResultItemFieldNames.IN_REPLY_TO_USER_ID, status.getInReplyToUserId()); result.put(QueryResultItemFieldNames.LATITUDE, lattitude); result.put(QueryResultItemFieldNames.LONGITUDE, longitude); result.put(QueryResultItemFieldNames.MENTIONS, newMap); result.put(QueryResultItemFieldNames.LANGUAGE, status.getLang()); result.put(QueryResultItemFieldNames.PLACE, place); result.put(QueryResultItemFieldNames.POSSIBLY_SENSITIVE, status.isPossiblySensitive()); result.put(QueryResultItemFieldNames.QUERY_NAME, queryName); result.put(QueryResultItemFieldNames.QUERY_OWNER, queryOwner); result.put(QueryResultItemFieldNames.QUERY, queryString); result.put(QueryResultItemFieldNames.RELEVANT_QUERY_TERMS, TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.put(QueryResultItemFieldNames.RETWEET, isRetweet); result.put(QueryResultItemFieldNames.RETWEET_COUNT, status.getRetweetCount()); result.put(QueryResultItemFieldNames.RETWEETED, status.isRetweeted()); result.put(QueryResultItemFieldNames.RETWEETED_BY_ME, status.isRetweetedByMe()); result.put(QueryResultItemFieldNames.RETWEET_STATUS_ID, retweetedId); result.put(QueryResultItemFieldNames.RETWEETED_TEXT, retweetedText); result.put(QueryResultItemFieldNames.SCOPES, StatusArraysHelper.getScopesList(status)); result.put(QueryResultItemFieldNames.SCREEN_NAME, status.getUser().getScreenName()); result.put(QueryResultItemFieldNames.SOURCE, (status.getSource())); result.put(QueryResultItemFieldNames.TEXT, (status.getText())); result.put(QueryResultItemFieldNames.TRUNCATED, status.isTruncated()); result.put(QueryResultItemFieldNames.URLS, StatusArraysHelper.getUrlsList(status)); result.put(QueryResultItemFieldNames.USER_ID, status.getUser().getId()); result.put(QueryResultItemFieldNames.USER_NAME, (status.getUser().getName())); result.put(QueryResultItemFieldNames.USER_DESCRIPTION, (status.getUser().getDescription())); result.put(QueryResultItemFieldNames.USER_LOCATION, (status.getUser().getLocation())); result.put(QueryResultItemFieldNames.USER_URL, (status.getUser().getURL())); result.put(QueryResultItemFieldNames.USER_IS_PROTECTED, status.getUser().isProtected()); result.put(QueryResultItemFieldNames.USER_FOLLOWERS_COUNT, status.getUser().getFollowersCount()); result.put(QueryResultItemFieldNames.USER_CREATED_AT, status.getUser().getCreatedAt()); result.put(QueryResultItemFieldNames.USER_FRIENDS_COUNT, status.getUser().getFriendsCount()); result.put(QueryResultItemFieldNames.USER_LISTED_COUNT, status.getUser().getListedCount()); result.put(QueryResultItemFieldNames.USER_STATUSES_COUNT, status.getUser().getStatusesCount()); result.put(QueryResultItemFieldNames.USER_FAVOURITES_COUNT, status.getUser().getFavouritesCount()); return result; }
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString, Status status) { TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro(); if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); result.setQueryName(queryName);//w w w . j av a 2 s. co m result.setQueryOwner(queryOwner); result.setQuery(queryString); result.setStatusId(status.getId()); result.setText(status.getText()); result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.setLang(status.getLang()); result.setCreatedAt(status.getCreatedAt().getTime()); User user = status.getUser(); result.setUserId(user.getId()); result.setScreenName(user.getScreenName()); result.setUserLocation(user.getLocation()); result.setUserName(user.getName()); result.setUserDescription(user.getDescription()); result.setUserIsProtected(user.isProtected()); result.setUserFollowersCount(user.getFollowersCount()); result.setUserCreatedAt(user.getCreatedAt().getTime()); result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt())); result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt())); result.setUserFriendsCount(user.getFriendsCount()); result.setUserListedCount(user.getListedCount()); result.setUserStatusesCount(user.getStatusesCount()); result.setUserFavoritesCount(user.getFavouritesCount()); result.setCurrentUserRetweetId(status.getCurrentUserRetweetId()); result.setInReplyToScreenName(status.getInReplyToScreenName()); result.setInReplyToStatusId(status.getInReplyToStatusId()); result.setInReplyToUserId(status.getInReplyToUserId()); if (status.getGeoLocation() != null) { result.setLatitude(status.getGeoLocation().getLatitude()); result.setLongitude(status.getGeoLocation().getLongitude()); } result.setSource(status.getSource()); result.setTrucated(status.isTruncated()); result.setPossiblySensitive(status.isPossiblySensitive()); result.setRetweet(status.getRetweetedStatus() != null); if (result.getRetweet()) { result.setRetweetStatusId(status.getRetweetedStatus().getId()); result.setRetweetedText(status.getRetweetedStatus().getText()); } result.setRetweeted(status.isRetweeted()); result.setRetweetCount(status.getRetweetCount()); result.setRetweetedByMe(status.isRetweetedByMe()); result.setFavoriteCount(status.getFavoriteCount()); result.setFavourited(status.isFavorited()); if (status.getPlace() != null) { result.setPlace(status.getPlace().getFullName()); } Scopes scopesObj = status.getScopes(); if (scopesObj != null) { List scopes = Arrays.asList(scopesObj.getPlaceIds()); result.setScopes(scopes); } return result; }
From source file:com.revolucion.secretwit.ui.timeline.TweetCellRenderer.java
License:Open Source License
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { setComponentOrientation(list.getComponentOrientation()); if (isSelected) { setBackground(list.getSelectionBackground()); setForeground(list.getSelectionForeground()); } else {//w ww. j a v a 2s . c o m // Check for rollover Color backgroundColor = list.getBackground(); ListUI ui = list.getUI(); if (ui instanceof TimelineListUI) { int rolledOverIndex = ((TimelineListUI) ui).getRolledOverIndex(); if (rolledOverIndex != -1 && rolledOverIndex == index) { backgroundColor = Colors.TIMELINE_ROLLOVER; } } setBackground(backgroundColor); setForeground(list.getForeground()); } setEnabled(list.isEnabled()); setFont(list.getFont()); Status status = (Status) value; if (status != null) { BufferedImage image = loadImage(status); labelIcon.setIcon(new ImageIcon(image)); labelDate.setText(new PrettyTime().format(status.getCreatedAt()) + " via " + parseSource(status)); labelUsername.setText(status.getUser().getScreenName()); labelRealname.setText(status.getUser().getName()); String statusText = status.getText(); areaMessage.setText(statusText); if (StegoUtils.doesProfileImageHaveWatermark(image)) { String decodedStatus = StegoUtils.decodeTweet(statusText); if (decodedStatus != null && !decodedStatus.isEmpty()) { labelSecret.setText(decodedStatus); labelSecret.setVisible(true); } else labelSecret.setVisible(false); } else labelSecret.setVisible(false); } return this; }
From source file:com.richardstansbury.tweetfollow.TwitterHelper.java
License:Open Source License
/** * Process's received Twitter status updates based upon the filter query. * * Implemented as part of the Status Listener Class. * @param status - a status update received by the listener. */// ww w. j av a2 s . co m @Override public void onStatus(Status status) { String tweetStr = status.getUser().getScreenName() + ": " + status.getText() + "(" + status.getCreatedAt() + ")"; _tweets.add(0, tweetStr); _parent.runOnUiThread(new Runnable() { @Override public void run() { _adapter.notifyDataSetChanged(); } }); }
From source file:com.rowland.hashtrace.utility.Utility.java
License:Apache License
public static Tweet createTweet(Status status) { User user = status.getUser();// w ww . j av a 2s.c o m long tweet_id = status.getId(); String tweet_text = status.getText(); Date tweet_text_date = status.getCreatedAt(); int tweet_retweet_count = status.getRetweetCount(); int tweet_favourite_count = status.getFavoriteCount(); int tweet_mentions_count = status.getUserMentionEntities().length; String user_name = user.getScreenName(); String user_image_url = user.getBiggerProfileImageURL(); String user_cover_url = user.getProfileBackgroundImageURL(); String user_location = user.getLocation(); String user_description = user.getDescription(); Tweet tweet = new Tweet(tweet_id, tweet_text, tweet_text_date, tweet_retweet_count, tweet_favourite_count, tweet_mentions_count, user_name, user_image_url, user_location, user_description, user_cover_url); return tweet; }