List of usage examples for twitter4j Status getRetweetCount
int getRetweetCount();
From source file:adapter.TwitterKeywordsAdapter.java
License:Apache License
@Override public void run() { while (true) { try {/*from www. jav a 2 s . c o 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.TwitterLanguageAdapter.java
License:Apache License
@Override public void run() { while (true) { try {/* w ww . j a v a 2s.com*/ 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 w w w . j a v a 2s. c o 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:au.net.moon.tUtils.twitterFields.java
License:Open Source License
/** * Get a <CODE>HashMap</CODE> of tweet fields by parsing a twitter4j Status * // w ww . ja va 2 s .co m * @param status * the twitter4j Status object * @return the tweet fields as name, value pairs in a <CODE>HashMap</CODE>. */ public static HashMap<String, String> parseStatusObj(Status status) { HashMap<String, String> splitFields = new HashMap<String, String>(); splitFields.put("createdAt", status.getCreatedAt().toString()); splitFields.put("id", Long.toString(status.getId())); splitFields.put("text", status.getText()); splitFields.put("source", status.getSource()); splitFields.put("isTruncated", status.isTruncated() ? "1" : "0"); splitFields.put("inReplyToStatusId", Long.toString(status.getInReplyToStatusId())); splitFields.put("inReplyToUserId", Long.toString(status.getInReplyToUserId())); splitFields.put("isFavorited", status.isFavorited() ? "1" : "0"); splitFields.put("inReplyToScreenName", status.getInReplyToScreenName()); if (status.getGeoLocation() != null) { splitFields.put("geoLocation", status.getGeoLocation().toString()); } else { splitFields.put("geoLocation", ""); } if (status.getPlace() != null) { splitFields.put("place", status.getPlace().toString()); } else { splitFields.put("place", ""); } splitFields.put("retweetCount", Long.toString(status.getRetweetCount())); splitFields.put("wasRetweetedByMe", status.isRetweetedByMe() ? "1" : "0"); String contributors = ""; if (status.getContributors() != null) { long[] tempContributors = status.getContributors(); for (int i = 0; i < tempContributors.length; i++) { contributors += Long.toString(tempContributors[i]); if (i != tempContributors.length - 1) { contributors += ", "; } } } splitFields.put("contributors", contributors); splitFields.put("annotations", ""); if (status.getRetweetedStatus() != null) { splitFields.put("retweetedStatus", "1"); } else { splitFields.put("retweetedStatus", "0"); } splitFields.put("userMentionEntities", status.getUserMentionEntities().toString()); splitFields.put("urlEntities", status.getURLEntities().toString()); splitFields.put("hashtagEntities", status.getHashtagEntities().toString()); splitFields.put("user", status.getUser().toString()); return splitFields; }
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 {//w w w . java 2s. 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()); }/* ww w . j a v a 2 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: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 w w.j ava 2 s . com 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:Collector.TweetCollector.java
public static void storeTweet(Status tweet) { BasicDBObject basicOBJ = new BasicDBObject(); basicOBJ.put("user_name", tweet.getUser().getScreenName()); basicOBJ.put("retweet_count", tweet.getRetweetCount()); basicOBJ.put("tweet_followers_count", tweet.getUser().getFollowersCount()); UserMentionEntity[] mentioned = tweet.getUserMentionEntities(); basicOBJ.put("tweet_mentioned_count", mentioned.length); basicOBJ.put("tweet_ID", tweet.getId()); basicOBJ.put("tweet_text", tweet.getText()); basicOBJ.put("created_at", tweet.getCreatedAt()); try {/* ww w .j a v a 2s . com*/ items.insert(basicOBJ); } catch (Exception e) { System.out.println("Could not store Tweet please try again" + e.getMessage()); } }
From source file:com.ahuralab.mozaic.db.Message.java
License:Open Source License
public static Message create(Status status) { User user = status.getUser();//from w ww. ja v a 2 s .c om return new Message(status.getText(), status.getCreatedAt(), status.getRetweetCount(), user.getId(), user.getName(), user.getScreenName(), user.getLocation(), user.getDescription(), user.getProfileImageURL(), status.getId(), 0, 0, user.getFollowersCount(), user.getStatusesCount()); }
From source file:com.daemon.database.Transactor.java
License:Open Source License
/** * Saves a given tweet in the DB if that tweet is not already saved. Only saves * the tweet no other information!/*from w w w .ja v a 2s . c o m*/ * * @param tweet The tweet to be saved. * @throws SQLException */ private void saveTweet(Status tweet, RegressionSentimentClassifier sentimentClassifier) throws SQLException { // for reweet, save the original tweet first if (tweet.getRetweetedStatus() != null) { saveAllTransactionSafe(tweet.getRetweetedStatus(), null, sentimentClassifier); } // then, save the current tweet // 1: Set Tweet ID prepStatementTweet.setLong(1, tweet.getId()); // 2 / 3: Set GeoLocation if (tweet.getGeoLocation() != null) { prepStatementTweet.setFloat(2, (float) tweet.getGeoLocation().getLatitude()); prepStatementTweet.setFloat(3, (float) tweet.getGeoLocation().getLongitude()); } else { prepStatementTweet.setNull(2, java.sql.Types.NULL); prepStatementTweet.setNull(3, java.sql.Types.NULL); } // 4: Set User ID prepStatementTweet.setLong(4, tweet.getUser().getId()); // 5: Set Reply-Tweet ID if (tweet.getInReplyToStatusId() == -1) { prepStatementTweet.setNull(5, java.sql.Types.NULL); } else { prepStatementTweet.setLong(5, tweet.getInReplyToStatusId()); } // 6: Set Retweet-ID if (tweet.getRetweetedStatus() != null) { prepStatementTweet.setLong(6, tweet.getRetweetedStatus().getId()); } else { prepStatementTweet.setNull(6, java.sql.Types.NULL); } // 7: Set Creation Date of Tweet java.sql.Timestamp sqlTimestamp = new java.sql.Timestamp(tweet.getCreatedAt().getTime()); prepStatementTweet.setTimestamp(7, sqlTimestamp); // 8-11: Other attributes: prepStatementTweet.setString(8, tweet.getSource()); prepStatementTweet.setString(9, tweet.getText()); prepStatementTweet.setString(10, tweet.getIsoLanguageCode()); prepStatementTweet.setInt(11, tweet.getRetweetCount()); // 12: Sentiment Float sentiment = sentimentClassifier.determineSentiment(tweet.getText(), tweet.getIsoLanguageCode()); if (sentiment == null) { prepStatementTweet.setNull(12, java.sql.Types.NULL); } else { prepStatementTweet.setFloat(12, sentimentClassifier.determineSentiment(tweet.getText(), tweet.getIsoLanguageCode())); } // execute statement prepStatementTweet.addBatch(); }