List of usage examples for twitter4j Status getId
long getId();
From source file:com.dhamacher.sentimentanalysis4tweets.database.Operator.java
License:Apache License
/** * Stores tweets inside the database//from www. j a v a2s . c om * @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 ww . j ava2s.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.loader.Twitter4JStatusLoader.java
License:Open Source License
@SuppressWarnings("unchecked") @Override// w w w . ja v a 2s . c om public SynchronizedStateSavedList<ParcelableStatus, Long> loadInBackground() { final SynchronizedStateSavedList<ParcelableStatus, Long> data = getData(); List<Status> statuses = null; final Context context = getContext(); final SharedPreferences prefs = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE); final int load_item_limit = prefs.getInt(PREFERENCE_KEY_LOAD_ITEM_LIMIT, PREFERENCE_DEFAULT_LOAD_ITEM_LIMIT); try { final Paging paging = new Paging(); paging.setCount(load_item_limit); if (mMaxId > 0) { paging.setMaxId(mMaxId); } if (mSinceId > 0) { paging.setSinceId(mSinceId); } statuses = getStatuses(paging); } catch (final TwitterException e) { e.printStackTrace(); } if (statuses != null) { final boolean insert_gap = load_item_limit == statuses.size() && data.size() > 0; final Status min_status = statuses.size() > 0 ? Collections.min(statuses) : null; final long min_status_id = min_status != null ? min_status.getId() : -1; for (final Status status : statuses) { final long id = status.getId(); deleteStatus(id); data.add(new ParcelableStatus(status, mAccountId, min_status_id > 0 && min_status_id == id && insert_gap, mInlineImagePreviewDisplayOption == INLINE_IMAGE_PREVIEW_DISPLAY_OPTION_CODE_LARGE_HIGH)); } } try { final List<ParcelableStatus> statuses_to_remove = new ArrayList<ParcelableStatus>(); for (final ParcelableStatus status : data) { if (isFiltered(context, status.screen_name, status.source, status.text_plain) && !status.is_gap) { statuses_to_remove.add(status); } } data.removeAll(statuses_to_remove); Collections.sort(data); } catch (final ConcurrentModificationException e) { Log.w(LOGTAG, e); } return data; }
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(); is_retweet = status.isRetweet();/* w ww .j a v a 2 s . co m*/ 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. jav a2s .c o 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.epsi.wks.api_wks_back.User.java
@GET @Path("/following/tweet") @Produces("application/json") public List<JSONObject> getUserFollowingsTweets(@PathParam("id") long userID) { Twitter twitter = UtilConfig.getTwitterInstance(); List<JSONObject> followingTweet = new ArrayList<>(); try {/* w ww . j a v a 2 s .com*/ PagableResponseList<twitter4j.User> userList = twitter.getFriendsList(userID, -1); for (twitter4j.User us : userList) { List<Status> statusFollower = twitter.getUserTimeline(us.getId()); for (Status sts : statusFollower) { JSONObject tweet = new JSONObject(); tweet.put("id", sts.getId()); tweet.put("text", sts.getText()); tweet.put("screen_name", sts.getUser().getScreenName()); tweet.put("name", sts.getUser().getName()); tweet.put("image_url", sts.getUser().getProfileImageURL()); followingTweet.add(tweet); } } } catch (TwitterException e) { } System.out.println("array" + String.valueOf(followingTweet.size())); return followingTweet; }
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 .ja v a 2s . co 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.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);// ww w . ja v a2 s .co 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)// ww w .j a v a2 s .c o 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; }