List of usage examples for twitter4j Status getUser
User getUser();
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Check search keywords./*from w ww . j a v a2s . c o m*/ */ public void checkSearch() { if (getTweetSearch().isEmpty()) { return; } log("Processing search", Level.FINE, getTweetSearch()); try { Network memory = getBot().memory().newMemory(); Vertex twitter = memory.createVertex(getPrimitive()); Vertex vertex = twitter.getRelationship(Primitive.LASTSEARCH); long last = 0; long max = 0; int count = 0; this.errors = 0; if (vertex != null) { last = ((Number) vertex.getData()).longValue(); } Set<Long> processed = new HashSet<Long>(); for (String tweetSearch : getTweetSearch()) { Query query = new Query(tweetSearch); if (vertex != null) { query.setSinceId(last); } SearchResource search = getConnection().search(); QueryResult result = search.search(query); List<Status> tweets = result.getTweets(); if (tweets != null) { log("Processing search results", Level.FINE, tweets.size(), tweetSearch); for (Status tweet : tweets) { if (count > this.maxSearch) { log("Max search results processed", Level.FINE, this.maxSearch); break; } if (tweet.getId() > last && !processed.contains(tweet.getId())) { if (tweet.getId() > max) { max = tweet.getId(); } boolean match = false; // Exclude replies/mentions if (getIgnoreReplies() && tweet.getText().indexOf('@') != -1) { log("Ignoring: Tweet is reply", Level.FINER, tweet.getText()); continue; } // Exclude retweets if (tweet.isRetweet()) { log("Ignoring: Tweet is retweet", Level.FINER, tweet.getText()); continue; } // Exclude protected if (tweet.getUser().isProtected()) { log("Ignoring: Tweet is protected", Level.FINER, tweet.getText()); continue; } // Exclude self if (tweet.getUser().getScreenName().equals(getUserName())) { log("Ignoring: Tweet is from myself", Level.FINER, tweet.getText()); continue; } // Ignore profanity if (Utils.checkProfanity(tweet.getText())) { log("Ignoring: Tweet contains profanity", Level.FINER, tweet.getText()); continue; } List<String> statusWords = new TextStream(tweet.getText().toLowerCase()).allWords(); for (String text : getStatusKeywords()) { List<String> keywords = new TextStream(text.toLowerCase()).allWords(); if (statusWords.containsAll(keywords)) { match = true; break; } } if (getLearn()) { learnTweet(tweet, true, true, memory); } if (match) { processed.add(tweet.getId()); log("Processing search", Level.INFO, tweet.getUser().getScreenName(), tweetSearch, tweet.getText()); input(tweet); Utils.sleep(500); count++; } else { if (!tweet.isRetweetedByMe()) { boolean found = false; // Check retweet. for (String keywords : getRetweet()) { List<String> keyWords = new TextStream(keywords).allWords(); if (!keyWords.isEmpty()) { if (statusWords.containsAll(keyWords)) { found = true; processed.add(tweet.getId()); count++; retweet(tweet); Utils.sleep(500); break; } } } if (!found) { log("Missing keywords", Level.FINER, tweet.getText()); } } else { log("Already retweeted", Level.FINER, tweet.getText()); } } } } } if (count > this.maxSearch) { break; } if (this.errors > this.maxErrors) { break; } } if (max != 0) { twitter.setRelationship(Primitive.LASTSEARCH, memory.createVertex(max)); memory.save(); } } catch (Exception exception) { log(exception); } // Wait for language processing. int count = 0; while (count < 60 && !getBot().memory().getActiveMemory().isEmpty()) { Utils.sleep(1000); } }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Check search keywords.//from w w w .ja va 2 s. c o m */ public void checkAutoFollowSearch(int friendCount) { if (getAutoFollowSearch().isEmpty()) { return; } log("Processing autofollow search", Level.FINE, getAutoFollowSearch()); try { Network memory = getBot().memory().newMemory(); Vertex twitter = memory.createVertex(getPrimitive()); Vertex vertex = twitter.getRelationship(Primitive.LASTAUTOFOLLOWSEARCH); long last = 0; long max = 0; int count = 0; if (vertex != null) { last = ((Number) vertex.getData()).longValue(); } for (String followSearch : getAutoFollowSearch()) { Query query = new Query(followSearch); if (vertex != null) { query.setSinceId(last); } SearchResource search = getConnection().search(); QueryResult result = search.search(query); List<Status> tweets = result.getTweets(); if (tweets != null) { for (Status tweet : tweets) { if (count > this.maxSearch) { break; } if (tweet.getId() > last) { log("Autofollow search", Level.FINE, tweet.getText(), tweet.getUser().getScreenName(), followSearch); if (checkFriendship(tweet.getUser().getId(), false)) { friendCount++; if (friendCount >= getMaxFriends()) { log("Max friend limit", Level.FINE, getMaxFriends()); return; } } count++; if (tweet.getId() > max) { max = tweet.getId(); } } } } if (count > this.maxSearch) { break; } } if (max != 0) { twitter.setRelationship(Primitive.LASTAUTOFOLLOWSEARCH, memory.createVertex(max)); memory.save(); } } catch (Exception exception) { log(exception); } }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Return the time-line.//from ww w . j a v a 2 s . c o m */ public List<String> getTimeline() { List<String> timeline = new ArrayList<String>(); try { ResponseList<Status> statuses = getConnection().getHomeTimeline(); for (Status status : statuses) { timeline.add(status.getCreatedAt() + " - <b>" + status.getUser().getScreenName() + "</b>: " + status.getText()); } } catch (Exception exception) { log(exception); throw new BotException(exception); } return timeline; }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Retweet the tweet./*from w w w . ja v a 2 s . c om*/ */ public void retweet(Status tweet) { if (tweet.isRetweet()) { tweet = tweet.getRetweetedStatus(); } if (tweet.getUser().isProtected()) { log("Cannot retweet protected user", Level.INFO, tweet.getUser().getScreenName(), tweet.getText()); return; } this.retweets++; log("Retweeting:", Level.INFO, tweet.getText(), tweet.getUser().getScreenName()); try { if (getConnection() == null) { connect(); } getConnection().retweetStatus(tweet.getId()); } catch (Exception exception) { if (exception.getMessage() != null && exception.getMessage().contains("authorized") && exception.getMessage().contains("endpoint")) { this.errors = this.errors + 5; } this.errors++; log(exception.toString(), Level.WARNING, tweet.getText()); } }
From source file:org.botlibre.sense.twitter.Twitter.java
License:Open Source License
/** * Process the email message.//w w w .j ava 2 s .c om */ @Override public void input(Object input, Network network) { if (!isEnabled()) { return; } try { if (input instanceof Status) { Status tweet = (Status) input; log("Processing status", Bot.FINE, tweet.getText(), tweet.getId()); if ((System.currentTimeMillis() - tweet.getCreatedAt().getTime()) > DAY) { log("Day old status", Bot.FINE, tweet.getId(), tweet.getCreatedAt().getTime()); return; } if (this.processedTweets.contains(tweet.getId())) { log("Already processed status", Bot.FINE, tweet.getText(), tweet.getId()); return; } this.processedTweets.add(tweet.getId()); String name = tweet.getUser().getScreenName(); String replyTo = tweet.getInReplyToScreenName(); String text = tweet.getText().trim(); TextStream stream = new TextStream(text); String firstWord = null; if (getIgnoreReplies()) { if (stream.peek() == '@') { stream.next(); String replyTo2 = stream.nextWord(); firstWord = stream.peekWord(); text = stream.upToEnd().trim(); if (!replyTo2.equals(replyTo)) { log("Reply to does not match:", Bot.FINE, replyTo2, replyTo); } replyTo = replyTo2; if (replyTo.equals(this.userName) && getFollowMessages()) { if ("follow".equals(firstWord)) { log("Adding friend", Level.INFO, tweet.getUser().getScreenName()); getConnection().createFriendship(tweet.getUser().getId()); } else if ("unfollow".equals(firstWord)) { log("Removing friend", Level.INFO, tweet.getUser().getScreenName()); getConnection().destroyFriendship(tweet.getUser().getId()); } } } } else { // Ignore the reply user, force the bot to reply. replyTo = null; } if (!tweet.isRetweet() && !tweet.getUser().isProtected()) { stream.reset(); List<String> words = stream.allWords(); for (String keywords : getRetweet()) { List<String> keyWords = new TextStream(keywords).allWords(); if (!keyWords.isEmpty()) { if (words.containsAll(keyWords)) { retweet(tweet); break; } } } } log("Input status", Level.FINE, tweet.getText(), name, replyTo); this.tweetsProcessed++; inputSentence(text, name, replyTo, tweet, network); } } catch (Exception exception) { log(exception); } }
From source file:org.brunocvcunha.taskerbox.impl.twitter.TwitterChannel.java
License:Apache License
@Override protected void execute() throws TwitterException { if (this.loggedUser == null) { setup();/*from w w w. j a v a2 s. c o m*/ } if (this.username != null) { logInfo(log, "Checking tweets of @" + this.username + " with @" + this.loggedUser); } else { logInfo(log, "Checking tweets with @" + this.loggedUser); } ResponseList<Status> statusList; if (this.username == null || this.username.equals("")) { statusList = this.twitter.getHomeTimeline(); } else { statusList = this.twitter.getUserTimeline(this.username); } status: for (Status status : statusList) { if (this.filter != null && !status.getText().contains(this.filter)) { continue; } StatusWrapper statusWrapper = new StatusWrapper(status); if (!alreadyPerformedAction(statusWrapper)) { if (this.ignoreUsers != null && this.ignoreUsers.contains(status.getUser().getScreenName())) { continue; } if (this.ignoreStarts != null) { for (String start : this.ignoreStarts) { if (status.getText().startsWith(start)) { continue status; } } } log.debug("Performing actions to entry: @" + status.getUser().getScreenName() + ": " + status.getText()); perform(statusWrapper); addAlreadyPerformedAction(statusWrapper); } } }
From source file:org.codice.ddf.catalog.twitter.source.TwitterSource.java
License:Open Source License
private Metacard getMetacard(Status status) { MetacardImpl metacard = new MetacardImpl(); metacard.setSourceId(id);/* w w w . j a va2 s . c om*/ metacard.setId(String.valueOf(status.getId())); metacard.setTitle(status.getText()); metacard.setMetadata("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" + "<Resource>" + "<name>" + status.getText() + "</name>" + "</Resource>"); metacard.setCreatedDate(status.getCreatedAt()); metacard.setModifiedDate(status.getCreatedAt()); metacard.setEffectiveDate(status.getCreatedAt()); metacard.setPointOfContact(status.getUser().getName()); if (status.getURLEntities() != null && status.getURLEntities().length > 0) { try { metacard.setResourceURI(new URI(status.getURLEntities()[0].getExpandedURL())); } catch (URISyntaxException e) { LOGGER.error("Unable to set resource URI.", e); } } else if (status.getMediaEntities() != null && status.getMediaEntities().length > 0) { try { metacard.setResourceURI(new URI(status.getMediaEntities()[0].getExpandedURL())); } catch (URISyntaxException e) { LOGGER.error("Unable to set resource URI.", e); } } else if (status.getExtendedMediaEntities() != null && status.getExtendedMediaEntities().length > 0) { try { metacard.setResourceURI(new URI(status.getExtendedMediaEntities()[0].getExpandedURL())); } catch (URISyntaxException e) { LOGGER.error("Unable to set resource URI.", e); } } GeoLocation geoLocation = status.getGeoLocation(); if (geoLocation != null) { metacard.setLocation("POINT (" + geoLocation.getLongitude() + " " + geoLocation.getLatitude() + ")"); } return metacard; }
From source file:org.examproject.tweet.service.SimpleTweetService.java
License:Apache License
private TweetDto mapStatus(Status status) { TweetDto tweetDto = new TweetDto(); tweetDto.setUserProfileImageURL(status.getUser().getProfileImageURL().toString()); tweetDto.setUserName(status.getUser().getScreenName()); tweetDto.setText(status.getText());//from w w w . ja v a2s . c o m tweetDto.setStatusId(String.valueOf(status.getId())); tweetDto.setCreated(status.getCreatedAt()); tweetDto.setIsFavorited(status.isFavorited()); tweetDto.setIsRetweetedByMe(status.isRetweetedByMe()); return tweetDto; }
From source file:org.gabrielebaldassarre.twitter.stream.tweet.TalendRowTweetBehaviour.java
License:Open Source License
public void visit(TalendFlow target) { ResourceBundle rb = ResourceBundle.getBundle("tTwitterStreamInput", Locale.getDefault()); valid = false;//from w w w . j a va 2 s . c o m if (status != null) { TalendRowFactory rowFactory = target.getModel().getRowFactory(); Status tweet = status; status = null; TalendRow current = rowFactory.newRow(target); Iterator<Entry<TalendColumn, TweetField>> col = associations.entrySet().iterator(); while (col.hasNext()) { List<String> h; List<Long> l; Map.Entry<TalendColumn, TweetField> row = (Map.Entry<TalendColumn, TweetField>) col.next(); if (target != null && !row.getKey().getFlow().equals(target)) { throw new IllegalArgumentException(String.format(rb.getString("exception.columnNotInFlow"), row.getKey().getName(), target.getName())); } switch (row.getValue()) { case CREATION_DATE: String literalDate = (new StringBuilder( TalendRowTweetBehaviour.DATEFORMAT.format(tweet.getCreatedAt()))).toString(); switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(literalDate)); case LONG: current.setValue(row.getKey(), Long.parseLong(literalDate)); case DOUBLE: current.setValue(row.getKey(), Double.parseDouble(literalDate)); case FLOAT: current.setValue(row.getKey(), Float.parseFloat(literalDate)); case INTEGER: current.setValue(row.getKey(), Integer.parseInt(literalDate)); case DATE: current.setValue(row.getKey(), tweet.getCreatedAt()); break; case STRING: current.setValue(row.getKey(), literalDate); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case FROM_NAME: switch (row.getKey().getType()) { case STRING: current.setValue(row.getKey(), tweet.getUser().getName()); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case FROM_USERID: switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(tweet.getUser().getId())); break; case DOUBLE: current.setValue(row.getKey(), new Double(tweet.getUser().getId())); break; case FLOAT: current.setValue(row.getKey(), new Float(tweet.getUser().getId())); break; case LONG: current.setValue(row.getKey(), new Long(tweet.getUser().getId())); break; case STRING: current.setValue(row.getKey(), String.valueOf((tweet.getUser().getId()))); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case FROM_SCREEN_NAME: switch (row.getKey().getType()) { case STRING: current.setValue(row.getKey(), tweet.getUser().getScreenName()); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case HASHTAGS: List<HashtagEntity> hashtags = Arrays.asList(tweet.getHashtagEntities()); h = new ArrayList<String>(hashtags.size()); for (HashtagEntity hashtag : hashtags) { h.add((includeHash() ? "#" : "") + hashtag.getText()); } switch (row.getKey().getType()) { case STRING: case LIST: current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h : Joiner.on(getEntitiesSeparator()).join(h)); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case IS_FAVORITED: switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(tweet.isFavorited() ? 1 : 0)); break; case BOOLEAN: current.setValue(row.getKey(), tweet.isFavorited()); break; case BYTE: current.setValue(row.getKey(), (byte) (tweet.isFavorited() ? 1 : 0)); break; case CHARACTER: current.setValue(row.getKey(), (tweet.isFavorited() ? '1' : '0')); break; case DOUBLE: current.setValue(row.getKey(), (double) (tweet.isFavorited() ? 1d : 0d)); break; case FLOAT: current.setValue(row.getKey(), (float) (tweet.isFavorited() ? 1f : 0f)); break; case INTEGER: current.setValue(row.getKey(), (tweet.isFavorited() ? 1 : 0)); break; case LONG: current.setValue(row.getKey(), (long) (tweet.isFavorited() ? 1l : 0l)); break; case SHORT: current.setValue(row.getKey(), (short) (tweet.isFavorited() ? (short) 1 : (short) 0)); break; case STRING: current.setValue(row.getKey(), (tweet.isFavorited() ? "1" : "0")); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case IS_POSSIBLY_SENSITIVE: switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(tweet.isPossiblySensitive() ? 1 : 0)); break; case BOOLEAN: current.setValue(row.getKey(), tweet.isPossiblySensitive()); break; case BYTE: current.setValue(row.getKey(), (byte) (tweet.isPossiblySensitive() ? 1 : 0)); break; case CHARACTER: current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? '1' : '0')); break; case DOUBLE: current.setValue(row.getKey(), (double) (tweet.isPossiblySensitive() ? 1d : 0d)); break; case FLOAT: current.setValue(row.getKey(), (float) (tweet.isPossiblySensitive() ? 1f : 0f)); break; case INTEGER: current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? 1 : 0)); break; case LONG: current.setValue(row.getKey(), (long) (tweet.isPossiblySensitive() ? 1l : 0l)); break; case SHORT: current.setValue(row.getKey(), (short) (tweet.isPossiblySensitive() ? (short) 1 : (short) 0)); break; case STRING: current.setValue(row.getKey(), (tweet.isPossiblySensitive() ? "1" : "0")); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case IS_RETWEET: switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(tweet.isRetweet() ? 1 : 0)); break; case BOOLEAN: current.setValue(row.getKey(), tweet.isRetweet()); break; case BYTE: current.setValue(row.getKey(), (byte) (tweet.isRetweet() ? 1 : 0)); break; case CHARACTER: current.setValue(row.getKey(), (tweet.isRetweet() ? '1' : '0')); break; case DOUBLE: current.setValue(row.getKey(), (double) (tweet.isRetweet() ? 1d : 0d)); break; case FLOAT: current.setValue(row.getKey(), (float) (tweet.isRetweet() ? 1f : 0f)); break; case INTEGER: current.setValue(row.getKey(), (tweet.isRetweet() ? 1 : 0)); break; case LONG: current.setValue(row.getKey(), (long) (tweet.isRetweet() ? 1l : 0l)); break; case SHORT: current.setValue(row.getKey(), (short) (tweet.isRetweet() ? (short) 1 : (short) 0)); break; case STRING: current.setValue(row.getKey(), (tweet.isRetweet() ? "1" : "0")); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } current.setValue(row.getKey(), tweet.isRetweet()); break; case LOCATION: GeoLocation g = tweet.getGeoLocation(); switch (row.getKey().getType()) { case STRING: current.setValue(row.getKey(), g != null ? String.valueOf(g.getLatitude()) + getEntitiesSeparator() + String.valueOf(g.getLongitude()) : null); break; case OBJECT: current.setValue(row.getKey(), g); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case REPLYTO_SCREEN_NAME: switch (row.getKey().getType()) { case STRING: current.setValue(row.getKey(), tweet.getInReplyToScreenName()); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case REPLYTO_STATUSID: switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(tweet.getInReplyToStatusId())); break; case DOUBLE: current.setValue(row.getKey(), new Double(tweet.getInReplyToStatusId())); break; case FLOAT: current.setValue(row.getKey(), new Float(tweet.getInReplyToStatusId())); break; case LONG: current.setValue(row.getKey(), new Long(tweet.getInReplyToStatusId())); break; case STRING: current.setValue(row.getKey(), String.valueOf((tweet.getInReplyToStatusId()))); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case REPLYTO_USERID: switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(tweet.getInReplyToUserId())); break; case DOUBLE: current.setValue(row.getKey(), new Double(tweet.getInReplyToUserId())); break; case FLOAT: current.setValue(row.getKey(), new Float(tweet.getInReplyToUserId())); break; case LONG: current.setValue(row.getKey(), new Long(tweet.getInReplyToUserId())); break; case STRING: current.setValue(row.getKey(), String.valueOf((tweet.getInReplyToUserId()))); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case RETWEET_COUNT: switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(tweet.getRetweetCount())); break; case DOUBLE: current.setValue(row.getKey(), new Double(tweet.getRetweetCount())); break; case FLOAT: current.setValue(row.getKey(), new Float(tweet.getRetweetCount())); break; case LONG: current.setValue(row.getKey(), new Long(tweet.getRetweetCount())); break; case STRING: current.setValue(row.getKey(), String.valueOf((tweet.getRetweetCount()))); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case SOURCE: switch (row.getKey().getType()) { case STRING: current.setValue(row.getKey(), tweet.getSource()); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case STATUS_ID: switch (row.getKey().getType()) { case BIGDECIMAL: current.setValue(row.getKey(), new BigDecimal(tweet.getId())); break; case DOUBLE: current.setValue(row.getKey(), new Double(tweet.getId())); break; case FLOAT: current.setValue(row.getKey(), new Float(tweet.getId())); break; case LONG: current.setValue(row.getKey(), new Long(tweet.getId())); break; case STRING: current.setValue(row.getKey(), String.valueOf((tweet.getId()))); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case TEXT: switch (row.getKey().getType()) { case STRING: current.setValue(row.getKey(), tweet.getText()); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case URL_ENTITIES: case URL_ENTITIES_STRING: List<URLEntity> urlEntities = Arrays.asList(tweet.getURLEntities()); h = new ArrayList<String>(urlEntities.size()); for (URLEntity urlEntity : urlEntities) { h.add(urlEntity.getExpandedURL()); } switch (row.getKey().getType()) { case STRING: case LIST: current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h : Joiner.on(getEntitiesSeparator()).join(h)); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case USER_MENTIONS: List<UserMentionEntity> userMentionsEntities = Arrays.asList(tweet.getUserMentionEntities()); l = new ArrayList<Long>(userMentionsEntities.size()); for (UserMentionEntity userMention : userMentionsEntities) { l.add(userMention.getId()); } switch (row.getKey().getType()) { case STRING: case LIST: current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? l : Joiner.on(getEntitiesSeparator()).join(l)); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; case USER_MENTIONS_SCREEN_NAME: List<UserMentionEntity> userMentionsScreen = Arrays.asList(tweet.getUserMentionEntities()); h = new ArrayList<String>(userMentionsScreen.size()); for (UserMentionEntity userMention : userMentionsScreen) { h.add((includeHash() ? "@" : "") + userMention.getScreenName()); } switch (row.getKey().getType()) { case STRING: case LIST: current.setValue(row.getKey(), !TalendType.STRING.equals(row.getKey().getType()) ? h : Joiner.on(getEntitiesSeparator()).join(h)); break; default: throw new IllegalArgumentException(String.format(rb.getString("exception.uncastableColumn"), row.getKey().getType().getTypeString(), row.getKey().getName())); } break; default: throw new IllegalArgumentException( String.format(rb.getString("exception.unparseableColumn"), row.getKey().getName())); } } } valid = true; }
From source file:org.gabrielebaldassarre.twitter.stream.tweet.TalendRowTweetBehaviour.java
License:Open Source License
private boolean filter(Status status) { if (filter_links && status.getURLEntities().length == 0) return false; if (excludes.length == 0 && froms.length == 0 && ats.length == 0) return true; HashtagEntity[] hashtagEntities = status.getHashtagEntities(); List<String> hashtagEntityList = new ArrayList<String>(); for (HashtagEntity hashtagEntity : hashtagEntities) { hashtagEntityList.add(hashtagEntity.getText()); }//w ww . j a v a 2s . c o m if (this.twitterLogicalOperator.equals(TwitterQueryBuilderLogicalOperator.AND)) { for (String exclude : excludes) { if (status.getText().contains(exclude)) return false; } for (String from : froms) { if (!status.getUser().getScreenName().equalsIgnoreCase(from)) return false; } for (String at : ats) { if (!hashtagEntityList.contains(at)) return false; } } else { for (String exclude : excludes) { if (!status.getText().contains(exclude)) return true; } for (String from : froms) { if (status.getUser().getScreenName().equalsIgnoreCase(from)) return true; } for (String at : ats) { if (hashtagEntityList.contains(at)) return true; } return false; } return true; }