List of usage examples for twitter4j Status getCreatedAt
Date getCreatedAt();
From source file:com.daiv.android.twitter.data.sq_lite.HomeDataSource.java
License:Apache License
public synchronized int insertTweets(List<Status> statuses, int currentAccount, long[] lastIds) { ContentValues[] valueses = new ContentValues[statuses.size()]; for (int i = 0; i < statuses.size(); i++) { Status status = statuses.get(i); Long id = status.getId(); ContentValues values = new ContentValues(); if (id > lastIds[0]) { String originalName = ""; long mId = status.getId(); long time = status.getCreatedAt().getTime(); if (status.isRetweet()) { originalName = status.getUser().getScreenName(); status = status.getRetweetedStatus(); }//from w w w . jav a 2 s . co m String[] html = TweetLinkUtils.getLinksInStatus(status); String text = html[0]; String media = html[1]; String url = html[2]; String hashtags = html[3]; String users = html[4]; String source; if (status.isRetweet()) { source = android.text.Html.fromHtml(status.getRetweetedStatus().getSource()).toString(); } else { source = android.text.Html.fromHtml(status.getSource()).toString(); } if (media.contains("/tweet_video/")) { media = media.replace("tweet_video", "tweet_video_thumb").replace(".mp4", ".png"); } values.put(HomeSQLiteHelper.COLUMN_ACCOUNT, currentAccount); values.put(HomeSQLiteHelper.COLUMN_TEXT, text); values.put(HomeSQLiteHelper.COLUMN_TWEET_ID, mId); values.put(HomeSQLiteHelper.COLUMN_NAME, status.getUser().getName()); values.put(HomeSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL()); values.put(HomeSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName()); values.put(HomeSQLiteHelper.COLUMN_TIME, time); values.put(HomeSQLiteHelper.COLUMN_RETWEETER, originalName); values.put(HomeSQLiteHelper.COLUMN_UNREAD, 1); values.put(HomeSQLiteHelper.COLUMN_PIC_URL, media); values.put(HomeSQLiteHelper.COLUMN_URL, url); values.put(HomeSQLiteHelper.COLUMN_USERS, users); values.put(HomeSQLiteHelper.COLUMN_HASHTAGS, hashtags); values.put(HomeSQLiteHelper.COLUMN_CLIENT_SOURCE, source); values.put(HomeSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, url)); values.put(HomeSQLiteHelper.COLUMN_CONVERSATION, status.getInReplyToStatusId() == -1 ? 0 : 1); } else { values = null; } valueses[i] = values; } ArrayList<ContentValues> vals = new ArrayList<ContentValues>(); for (ContentValues v : valueses) { if (v != null) { vals.add(v); } } insertMultiple(valueses); return vals.size(); }
From source file:com.daiv.android.twitter.data.sq_lite.ListDataSource.java
License:Apache License
public synchronized void createTweet(Status status, long listId) { ContentValues values = new ContentValues(); String originalName = ""; long time = status.getCreatedAt().getTime(); long id = status.getId(); if (status.isRetweet()) { originalName = status.getUser().getScreenName(); status = status.getRetweetedStatus(); }//from w ww . j a v a2 s.c o m String[] html = TweetLinkUtils.getLinksInStatus(status); String text = html[0]; String media = html[1]; String url = 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(ListSQLiteHelper.COLUMN_TEXT, text); values.put(ListSQLiteHelper.COLUMN_TWEET_ID, id); values.put(ListSQLiteHelper.COLUMN_NAME, status.getUser().getName()); values.put(ListSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL()); values.put(ListSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName()); values.put(ListSQLiteHelper.COLUMN_TIME, time); values.put(ListSQLiteHelper.COLUMN_RETWEETER, originalName); values.put(ListSQLiteHelper.COLUMN_PIC_URL, media); values.put(ListSQLiteHelper.COLUMN_URL, url); values.put(ListSQLiteHelper.COLUMN_USERS, users); values.put(ListSQLiteHelper.COLUMN_HASHTAGS, hashtags); values.put(ListSQLiteHelper.COLUMN_LIST_ID, listId); values.put(ListSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, url)); try { database.insert(ListSQLiteHelper.TABLE_HOME, null, values); } catch (Exception e) { open(); database.insert(ListSQLiteHelper.TABLE_HOME, null, values); } }
From source file:com.daiv.android.twitter.data.sq_lite.ListDataSource.java
License:Apache License
public int insertTweets(List<Status> statuses, long listId) { 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 time = status.getCreatedAt().getTime(); long id = status.getId(); if (status.isRetweet()) { originalName = status.getUser().getScreenName(); status = status.getRetweetedStatus(); }/*from w w w . ja v a 2 s . c o m*/ String[] html = TweetLinkUtils.getLinksInStatus(status); String text = html[0]; String media = html[1]; String url = 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(ListSQLiteHelper.COLUMN_TEXT, text); values.put(ListSQLiteHelper.COLUMN_TWEET_ID, id); values.put(ListSQLiteHelper.COLUMN_NAME, status.getUser().getName()); values.put(ListSQLiteHelper.COLUMN_PRO_PIC, status.getUser().getOriginalProfileImageURL()); values.put(ListSQLiteHelper.COLUMN_SCREEN_NAME, status.getUser().getScreenName()); values.put(ListSQLiteHelper.COLUMN_TIME, time); values.put(ListSQLiteHelper.COLUMN_RETWEETER, originalName); values.put(ListSQLiteHelper.COLUMN_PIC_URL, media); values.put(ListSQLiteHelper.COLUMN_URL, url); values.put(ListSQLiteHelper.COLUMN_USERS, users); values.put(ListSQLiteHelper.COLUMN_HASHTAGS, hashtags); values.put(ListSQLiteHelper.COLUMN_LIST_ID, listId); values.put(ListSQLiteHelper.COLUMN_ANIMATED_GIF, TweetLinkUtils.getGIFUrl(status, url)); valueses[i] = values; } return insertMultiple(valueses); }
From source file:com.daiv.android.twitter.data.sq_lite.MentionsDataSource.java
License:Apache License
public synchronized void createTweet(Status status, int account, boolean initial) { ContentValues values = new ContentValues(); String originalName = ""; long id = status.getId(); long time = status.getCreatedAt().getTime(); String[] html = TweetLinkUtils.getLinksInStatus(status); String text = html[0];//from www. j a v a 2s . c o 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, 0); values.put(MentionsSQLiteHelper.COLUMN_PIC_URL, media); values.put(MentionsSQLiteHelper.COLUMN_URL, otherUrl); values.put(MentionsSQLiteHelper.COLUMN_PIC_URL, media); 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); try { database.insert(MentionsSQLiteHelper.TABLE_MENTIONS, null, values); } catch (Exception e) { open(); database.insert(MentionsSQLiteHelper.TABLE_MENTIONS, null, values); } }
From source file:com.daiv.android.twitter.data.sq_lite.MentionsDataSource.java
License:Apache License
public synchronized void createTweet(Status status, int account) { 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 a2s.c o 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); try { database.insert(MentionsSQLiteHelper.TABLE_MENTIONS, null, values); } catch (Exception e) { open(); database.insert(MentionsSQLiteHelper.TABLE_MENTIONS, null, values); } }
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];//from www . j ava2 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.ui.tweet_viewer.fragments.TweetFragment.java
License:Apache License
public void getInfo(final View favButton, final TextView favCount, final TextView retweetCount, final long tweetId, final View retweetButton) { Thread getInfo = new Thread(new Runnable() { @Override/*from w w w . java 2 s. c o m*/ public void run() { String location = ""; String via = ""; long realTime = 0; boolean retweetedByMe = false; try { Twitter twitter = getTwitter(); TwitterMultipleImageHelper helper = new TwitterMultipleImageHelper(); status = twitter.showStatus(tweetId); ArrayList<String> i = new ArrayList<String>(); if (picture) { i = helper.getImageURLs(status, twitter); } final ArrayList<String> images = i; GeoLocation loc = status.getGeoLocation(); try { Geocoder geocoder = new Geocoder(context, Locale.getDefault()); List<Address> addresses = geocoder.getFromLocation(loc.getLatitude(), loc.getLongitude(), 1); if (addresses.size() > 0) { Address address = addresses.get(0); location += address.getLocality() + ", " + address.getCountryName(); } else { location = ""; } } catch (Exception x) { location = ""; } via = android.text.Html.fromHtml(status.getSource()).toString(); final String sfavCount; if (status.isRetweet()) { twitter4j.Status status2 = status.getRetweetedStatus(); via = android.text.Html.fromHtml(status2.getSource()).toString(); realTime = status2.getCreatedAt().getTime(); sfavCount = status2.getFavoriteCount() + ""; } else { realTime = status.getCreatedAt().getTime(); sfavCount = status.getFavoriteCount() + ""; } retweetedByMe = status.isRetweetedByMe(); final String retCount = "" + status.getRetweetCount(); final String timeDisplay; if (!settings.militaryTime) { timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.US).format(realTime) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.US).format(realTime); } else { timeDisplay = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.GERMAN).format(realTime) + " " + DateFormat.getTimeInstance(DateFormat.SHORT, Locale.GERMAN).format(realTime); } final String fVia = " " + getResources().getString(R.string.via) + " " + via; final String fLoc = location.equals("") ? "" : "\n" + location; final boolean fRet = retweetedByMe; final long fTime = realTime; final Status fStatus = status; ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { // you can't retweet a protected account if (status.getUser().isProtected()) { retweetButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Toast.makeText(context, getString(R.string.protected_account), Toast.LENGTH_SHORT).show(); } }); } retweetCount.setText(" " + retCount); if (retweetButton instanceof ImageButton) { if (fRet) { if (!settings.addonTheme) { ((ImageButton) retweetButton) .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { ((ImageButton) retweetButton).setColorFilter(settings.accentInt); } } else { ((ImageButton) retweetButton).clearColorFilter(); } } else { if (fRet) { if (!settings.addonTheme) { retweetButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { retweetButton.setBackgroundColor(settings.accentInt); } } else { retweetButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } timetv.setText(timeDisplay + fVia); timetv.append(fLoc); favCount.setText(" " + sfavCount); if (favButton instanceof ImageButton) { if (fStatus.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { ((ImageButton) favButton) .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { ((ImageButton) favButton).setColorFilter(settings.accentInt); } ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); isFavorited = true; } else { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); isFavorited = false; ((ImageButton) favButton).clearColorFilter(); } } else { if (fStatus.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { favButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { favButton.setBackgroundColor(settings.accentInt); } isFavorited = true; } else { isFavorited = false; favButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } for (String s : images) { Log.v("Test_image", s); } } }); } catch (Exception e) { } } }); getInfo.setPriority(Thread.MAX_PRIORITY); getInfo.start(); }
From source file:com.dhamacher.sentimentanalysis4tweets.common.LocalTweet.java
License:Apache License
public void copyFrom(Status tweet) { setId(tweet.getId());/* w ww .j a v a 2 s.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 ww . ja v a 2 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. j a v a 2 s .c o m*/ 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(); }