List of usage examples for twitter4j Status getFavoriteCount
int getFavoriteCount();
From source file:adapter.TwitterKeywordsAdapter.java
License:Apache License
@Override public void run() { while (true) { try {//from w ww . j a va2s .c om Status status = this.messageQueue.take(); Event event = new Event(); Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(), status.getUser().getScreenName(), status.getUser().getLang(), status.getUser().getFollowersCount(), status.getUser().getFriendsCount(), status.getHashtagEntities(), status.getFavoriteCount(), status.getRetweetCount(), status.getGeoLocation()); eventCount++; // cantReplicas: Cantidad de PEs que se quieren generar para el proximo operador // Nota: recuerden que la topologa no necesariamente deba ser de este estilo // tambin poda ser por un hash int cantReplicas = 10; event.put("levelTweet", Integer.class, eventCount % cantReplicas); event.put("id", Integer.class, eventCount); event.put("tweet", Tweet.class, tweet); getRemoteStream().put(event); } catch (Exception e) { logger.error("Error: " + e); logger.error("Error al crear evento"); } } }
From source file:adapter.TwitterLanguageAdapter.java
License:Apache License
@Override public void run() { while (true) { try {/*from ww w . ja v a 2 s . co m*/ Status status = this.messageQueue.take(); Event event = new Event(); Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(), status.getUser().getScreenName(), status.getUser().getLang(), status.getUser().getFollowersCount(), status.getUser().getFriendsCount(), status.getHashtagEntities(), status.getFavoriteCount(), status.getRetweetCount(), status.getGeoLocation()); eventCount++; // cantReplicas: Cantidad de PEs que se quieren generar para el proximo operador // Nota: recuerden que la topologa no necesariamente deba ser de este estilo // tambin poda ser por un hash int cantReplicas = 10; event.put("levelTweet", Integer.class, eventCount % cantReplicas); event.put("id", Integer.class, eventCount); event.put("tweet", Tweet.class, tweet); getRemoteStream().put(event); } catch (Exception e) { logger.error("Error: " + e); logger.error("Error al crear evento"); } } }
From source file:adapter.TwitterLocationAdapter.java
License:Apache License
@Override public void run() { while (true) { try {//from ww w . j a v a2s . co m Status status = this.messageQueue.take(); Event event = new Event(); Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(), status.getUser().getScreenName(), status.getUser().getLang(), status.getUser().getFollowersCount(), status.getUser().getFriendsCount(), status.getHashtagEntities(), status.getFavoriteCount(), status.getRetweetCount(), status.getGeoLocation()); eventCount++; // cantReplicas: Cantidad de PEs que se quieren generar para el // proximo operador // Nota: recuerden que la topologa no necesariamente deba ser // de este estilo // tambin poda ser por un hash int cantReplicas = 10; event.put("levelTweet", Integer.class, eventCount % cantReplicas); event.put("id", Integer.class, eventCount); event.put("tweet", Tweet.class, tweet); getRemoteStream().put(event); } catch (Exception e) { logger.error("Error: " + e); logger.error("Error al crear evento"); } } }
From source file:bditac.TwitterCaptura.java
public static void main(String[] args) throws TwitterException { int criid, apiid, capid; if (args.length == 3) { criid = Integer.parseInt(args[0]); apiid = Integer.parseInt(args[1]); capid = Integer.parseInt(args[2]); } else {/*from w ww .j ava2s. c o m*/ criid = 1; apiid = 1; capid = 1; } CriseJpaController crijpa = new CriseJpaController(factory); Crise crise = crijpa.findCrise(criid); CriseApiJpaController criapijpa = new CriseApiJpaController(factory); CriseApi criapi = criapijpa.findCriseApi(capid); ApiJpaController apijpa = new ApiJpaController(factory); Api api = apijpa.findApi(apiid); CidadeJpaController cidjpa = new CidadeJpaController(factory); Cidade cidade = cidjpa.findCidade(crise.getCidId()); String coords[] = crise.getCriRegiao().split(","); TwitterGeo geo = new TwitterGeo(coords, cidade.getCidNome(), crise.getCriGeotipo()); Thread threadGeo = new Thread(geo); TwitterMens mens = new TwitterMens(crise.getCrtId()); Thread threadMens = new Thread(mens); TwitterGravar gravar = new TwitterGravar(); Thread threadGravar = new Thread(gravar); threadGeo.setName("ThreadGeo"); threadGeo.start(); threadMens.setName("ThreadMens"); threadMens.start(); threadGravar.setName("ThreadGravar"); threadGravar.start(); ConfigurationBuilder cb = new ConfigurationBuilder(); cb.setDebugEnabled(true).setOAuthConsumerKey(criapi.getCapKey()) .setOAuthConsumerSecret(criapi.getCapSecret()).setOAuthAccessToken(criapi.getCapToken()) .setOAuthAccessTokenSecret(criapi.getCapTokenSecret()); TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance(); String texto = "[\\xF0\\x9F]"; StatusListener listener; listener = new StatusListener() { int cont = 0; @Override public void onStatus(Status status) { if (!(status.getText().contains(texto) || status.getText().isEmpty())) { Ocorrencia ocor = new Ocorrencia(); ocor.setApiId(apiid); ocor.setCriId(criid); ocor.setCapId(capid); ocor.setOcrIdApi(status.getId()); ocor.setOcrCriacao(status.getCreatedAt()); ocor.setOcrTexto(status.getText()); // System.out.println(ocor.getOcrTexto()); ocor.setOcrUsuId(status.getUser().getId()); ocor.setOcrUsuNome(status.getUser().getName()); ocor.setOcrUsuScreenNome(status.getUser().getScreenName()); ocor.setOcrFonte(status.getSource()); ocor.setOcrLingua(status.getLang()); ocor.setOcrFavorite(status.getFavoriteCount()); ocor.setOcrRetweet(status.getRetweetCount()); String coords = ""; if (status.getPlace() == null) { ocor.setOcrPaisCodigo(""); ocor.setOcrPais(""); ocor.setOcrLocal(""); } else { ocor.setOcrPaisCodigo(status.getPlace().getCountryCode()); ocor.setOcrPais(status.getPlace().getCountry()); ocor.setOcrLocal(status.getPlace().getFullName()); GeoLocation locs[][] = status.getPlace().getBoundingBoxCoordinates(); for (int x = 0; x < locs.length; x++) { for (int y = 0; y < locs[x].length; y++) { coords += "[" + locs[x][y].getLongitude() + "," + locs[x][y].getLatitude() + "]"; if (!(x == locs.length - 1 && y == locs[x].length - 1)) { coords += ","; } } } } ocor.setOcrCoordenadas(coords); ocor.setOcrGeo('0'); ocor.setOcrIdentificacao('0'); ocor.setOcrIdenper(0.0f); ocor.setOcrGravado('0'); ocor.setOcrSentimento('0'); ocor.setOcrTempo('0'); boolean add = ocors.add(ocor); cont++; if (ocors.size() > 1000) { Limpar(); } // System.out.println(cont+" - "+status.getId() + " - " + status.getCreatedAt() + status.getPlace().getFullName()); } } @Override public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) { System.out.println("Got a status deletion notice id:" + statusDeletionNotice.getStatusId()); } @Override public void onTrackLimitationNotice(int numberOfLimitedStatuses) { System.out.println("Got track limitation notice:" + numberOfLimitedStatuses); } @Override public void onScrubGeo(long userId, long upToStatusId) { System.out.println("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId); } @Override public void onStallWarning(StallWarning warning) { System.out.println("Got stall warning:" + warning); } @Override public void onException(Exception ex) { ex.printStackTrace(); } private void Limpar() { while (!threadGeo.isInterrupted()) { threadGeo.interrupt(); } while (!threadMens.isInterrupted()) { threadMens.interrupt(); } while (!threadGravar.isInterrupted()) { threadGravar.interrupt(); } boolean achou = true; int x = 0; System.out.println("Removendo: " + ocors.size()); while (x < ocors.size()) { if (ocors.get(x).getOcrGravado() != '0') { ocors.remove(x); } else { x++; } } System.out.println("Final: " + ocors.size()); if (!threadGeo.isAlive()) { threadGeo.start(); } if (!threadMens.isAlive()) { threadMens.start(); } if (!threadGravar.isAlive()) { threadGravar.start(); } } }; FilterQuery filter = new FilterQuery(); double[][] location = new double[2][2]; location[0][0] = Double.parseDouble(coords[0]); location[0][1] = Double.parseDouble(coords[1]); location[1][0] = Double.parseDouble(coords[4]); location[1][1] = Double.parseDouble(coords[5]); filter.locations(location); twitterStream.addListener(listener); twitterStream.filter(filter); }
From source file:co.cask.cdap.template.etl.realtime.source.TwitterSource.java
License:Apache License
private StructuredRecord convertTweet(Status tweet) { StructuredRecord.Builder recordBuilder = StructuredRecord.builder(this.schema); recordBuilder.set(ID, tweet.getId()); recordBuilder.set(MSG, tweet.getText()); recordBuilder.set(LANG, tweet.getLang()); Date tweetDate = tweet.getCreatedAt(); if (tweetDate != null) { recordBuilder.set(TIME, tweetDate.getTime()); }//from w ww . ja v a 2 s . co m recordBuilder.set(FAVC, tweet.getFavoriteCount()); recordBuilder.set(RTC, tweet.getRetweetCount()); recordBuilder.set(SRC, tweet.getSource()); if (tweet.getGeoLocation() != null) { recordBuilder.set(GLAT, tweet.getGeoLocation().getLatitude()); recordBuilder.set(GLNG, tweet.getGeoLocation().getLongitude()); } recordBuilder.set(ISRT, tweet.isRetweet()); return recordBuilder.build(); }
From source file:co.cask.hydrator.plugin.realtime.source.TwitterSource.java
License:Apache License
private StructuredRecord convertTweet(Status tweet) { StructuredRecord.Builder recordBuilder = StructuredRecord.builder(SCHEMA); recordBuilder.set(ID, tweet.getId()); recordBuilder.set(MSG, tweet.getText()); recordBuilder.set(LANG, tweet.getLang()); Date tweetDate = tweet.getCreatedAt(); if (tweetDate != null) { recordBuilder.set(TIME, tweetDate.getTime()); }/*from w ww .ja v a2 s .c o m*/ recordBuilder.set(FAVC, tweet.getFavoriteCount()); recordBuilder.set(RTC, tweet.getRetweetCount()); recordBuilder.set(SRC, tweet.getSource()); if (tweet.getGeoLocation() != null) { recordBuilder.set(GLAT, tweet.getGeoLocation().getLatitude()); recordBuilder.set(GLNG, tweet.getGeoLocation().getLongitude()); } recordBuilder.set(ISRT, tweet.isRetweet()); return recordBuilder.build(); }
From source file:com.daiv.android.twitter.adapters.TimelineArrayAdapter.java
License:Apache License
public void getFavoriteCount(final ViewHolder holder, final long tweetId) { Thread getCount = new Thread(new Runnable() { @Override// ww w . j a va2 s .c om public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); final Status status; if (holder.retweeter.getVisibility() != View.GONE) { status = twitter.showStatus(holder.tweetId).getRetweetedStatus(); } else { status = twitter.showStatus(tweetId); } if (status != null && holder.tweetId == tweetId) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { holder.favCount.setText(" " + status.getFavoriteCount()); if (status.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { holder.favorite .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { holder.favorite.setColorFilter(settings.accentInt); } holder.favorite.setImageDrawable(context.getResources().getDrawable(resource)); holder.isFavorited = true; } else { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); holder.favorite.setImageDrawable(context.getResources().getDrawable(resource)); holder.isFavorited = false; holder.favorite.clearColorFilter(); } } }); } } catch (Exception e) { } } }); getCount.setPriority(7); getCount.start(); }
From source file:com.daiv.android.twitter.adapters.TimelineArrayAdapter.java
License:Apache License
public void getCounts(final ViewHolder holder, final long tweetId) { Thread getCount = new Thread(new Runnable() { @Override/*w w w.j a v a 2s . com*/ public void run() { try { Twitter twitter = Utils.getTwitter(context, settings); final Status status; status = twitter.showStatus(tweetId); if (status != null) { ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { holder.favCount.setText(" " + status.getFavoriteCount()); holder.retweetCount.setText(" " + status.getRetweetCount()); if (status.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (!settings.addonTheme) { holder.favorite .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { holder.favorite.setColorFilter(settings.accentInt); } holder.favorite.setImageDrawable(context.getResources().getDrawable(resource)); holder.isFavorited = true; } else { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); holder.favorite.setImageDrawable(context.getResources().getDrawable(resource)); holder.isFavorited = false; holder.favorite.clearColorFilter(); } if (status.isRetweetedByMe()) { if (!settings.addonTheme) { holder.retweet .setColorFilter(context.getResources().getColor(R.color.app_color)); } else { holder.retweet.setColorFilter(settings.accentInt); } } else { holder.retweet.clearColorFilter(); } } }); } } catch (Exception e) { e.printStackTrace(); } } }); getCount.setPriority(7); getCount.start(); }
From source file:com.daiv.android.twitter.ui.tweet_viewer.fragments.TweetFragment.java
License:Apache License
public void getFavoriteCount(final TextView favs, final View favButton, final long tweetId) { new Thread(new Runnable() { @Override// www . ja va2 s. c o m public void run() { try { Twitter twitter = getTwitter(); twitter4j.Status status = twitter.showStatus(tweetId); if (status.isRetweet()) { twitter4j.Status retweeted = status.getRetweetedStatus(); status = retweeted; } final twitter4j.Status fStatus = status; ((Activity) context).runOnUiThread(new Runnable() { @Override public void run() { favs.setText(" " + fStatus.getFavoriteCount()); if (fStatus.isFavorited()) { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.favoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (favButton instanceof ImageButton) { 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)); } else if (favButton instanceof LinearLayout) { if (!settings.addonTheme) { favButton.setBackgroundColor( context.getResources().getColor(R.color.app_color)); } else { favButton.setBackgroundColor(settings.accentInt); } } isFavorited = true; } else { TypedArray a = context.getTheme() .obtainStyledAttributes(new int[] { R.attr.notFavoritedButton }); int resource = a.getResourceId(0, 0); a.recycle(); if (favButton instanceof ImageButton) { ((ImageButton) favButton) .setImageDrawable(context.getResources().getDrawable(resource)); isFavorited = false; ((ImageButton) favButton).clearColorFilter(); } else { favButton.setBackgroundColor( getResources().getColor(android.R.color.transparent)); } } } }); } catch (Exception e) { } } }).start(); }
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/* ww w .j av a2s .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(); }