List of usage examples for twitter4j Status getId
long getId();
From source file:org.apache.asterix.external.parser.TweetParser.java
License:Apache License
@Override public void parse(IRawRecord<? extends Status> record, DataOutput out) throws HyracksDataException { Status tweet = record.get(); User user = tweet.getUser();//w w w . j a v a2 s . c om // Tweet user data ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.SCREEN_NAME)]) .setValue(JObjectUtil.getNormalizedString(user.getScreenName())); ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.LANGUAGE)]) .setValue(JObjectUtil.getNormalizedString(user.getLang())); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.FRIENDS_COUNT)]) .setValue(user.getFriendsCount()); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.STATUS_COUNT)]) .setValue(user.getStatusesCount()); ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.NAME)]) .setValue(JObjectUtil.getNormalizedString(user.getName())); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.FOLLOWERS_COUNT)]) .setValue(user.getFollowersCount()); // Tweet data ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.ID)]) .setValue(String.valueOf(tweet.getId())); int userPos = tweetFieldNameMap.get(Tweet.USER); for (int i = 0; i < mutableUserFields.length; i++) { ((AMutableRecord) mutableTweetFields[userPos]).setValueAtPos(i, mutableUserFields[i]); } if (tweet.getGeoLocation() != null) { ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LATITUDE)]) .setValue(tweet.getGeoLocation().getLatitude()); ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LONGITUDE)]) .setValue(tweet.getGeoLocation().getLongitude()); } else { ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LATITUDE)]).setValue(0); ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LONGITUDE)]).setValue(0); } ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.CREATED_AT)]) .setValue(JObjectUtil.getNormalizedString(tweet.getCreatedAt().toString())); ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.MESSAGE)]) .setValue(JObjectUtil.getNormalizedString(tweet.getText())); for (int i = 0; i < mutableTweetFields.length; i++) { mutableRecord.setValueAtPos(i, mutableTweetFields[i]); } recordBuilder.reset(mutableRecord.getType()); recordBuilder.init(); IDataParser.writeRecord(mutableRecord, out, recordBuilder); }
From source file:org.apache.asterix.external.util.TweetProcessor.java
License:Apache License
public AMutableRecord processNextTweet(Status tweet) { User user = tweet.getUser();/*from w ww.j av a 2 s . co m*/ // Tweet user data ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.SCREEN_NAME)]) .setValue(JObjectUtil.getNormalizedString(user.getScreenName())); ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.LANGUAGE)]) .setValue(JObjectUtil.getNormalizedString(user.getLang())); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.FRIENDS_COUNT)]) .setValue(user.getFriendsCount()); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.STATUS_COUNT)]) .setValue(user.getStatusesCount()); ((AMutableString) mutableUserFields[userFieldNameMap.get(Tweet.NAME)]) .setValue(JObjectUtil.getNormalizedString(user.getName())); ((AMutableInt32) mutableUserFields[userFieldNameMap.get(Tweet.FOLLOWERS_COUNT)]) .setValue(user.getFollowersCount()); // Tweet data ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.ID)]) .setValue(String.valueOf(tweet.getId())); int userPos = tweetFieldNameMap.get(Tweet.USER); for (int i = 0; i < mutableUserFields.length; i++) { ((AMutableRecord) mutableTweetFields[userPos]).setValueAtPos(i, mutableUserFields[i]); } if (tweet.getGeoLocation() != null) { ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LATITUDE)]) .setValue(tweet.getGeoLocation().getLatitude()); ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LONGITUDE)]) .setValue(tweet.getGeoLocation().getLongitude()); } else { ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LATITUDE)]).setValue(0); ((AMutableDouble) mutableTweetFields[tweetFieldNameMap.get(Tweet.LONGITUDE)]).setValue(0); } ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.CREATED_AT)]) .setValue(JObjectUtil.getNormalizedString(tweet.getCreatedAt().toString())); ((AMutableString) mutableTweetFields[tweetFieldNameMap.get(Tweet.MESSAGE)]) .setValue(JObjectUtil.getNormalizedString(tweet.getText())); for (int i = 0; i < mutableTweetFields.length; i++) { mutableRecord.setValueAtPos(i, mutableTweetFields[i]); } return mutableRecord; }
From source file:org.apache.blur.demo.twitter.TwitterSearchQueueReader.java
License:Apache License
private RowMutation toRowMutation(Status tweet) { RowMutation rowMutation = new RowMutation(); rowMutation.setRowId(tweet.getUser().getScreenName()); rowMutation.setTable(tableName);/*from www.j av a 2s. c om*/ rowMutation.setRowMutationType(RowMutationType.UPDATE_ROW); Record record = new Record(); record.setFamily("tweets"); record.setRecordId(tweet.getUser().getScreenName() + "-" + tweet.getId()); record.addToColumns(new Column("message", tweet.getText())); for (UserMentionEntity mention : tweet.getUserMentionEntities()) { record.addToColumns(new Column("mentions", mention.getScreenName())); } for (HashtagEntity tag : tweet.getHashtagEntities()) { record.addToColumns(new Column("hashtags", tag.getText())); } rowMutation.addToRecordMutations(new RecordMutation(RecordMutationType.REPLACE_ENTIRE_RECORD, record)); log.trace(rowMutation); return rowMutation; }
From source file:org.apache.camel.component.twitter.consumer.search.SearchConsumer.java
License:Apache License
private List<Status> search(Query query) throws TwitterException { Integer numberOfPages = 1;/*from ww w . j a v a 2 s.c o m*/ if (ObjectHelper.isNotEmpty(te.getProperties().getLang())) { query.setLang(te.getProperties().getLang()); } if (ObjectHelper.isNotEmpty(te.getProperties().getCount())) { query.setCount(te.getProperties().getCount()); } if (ObjectHelper.isNotEmpty(te.getProperties().getNumberOfPages())) { numberOfPages = te.getProperties().getNumberOfPages(); } LOG.debug("Searching with " + numberOfPages + " pages."); Twitter twitter = te.getProperties().getTwitter(); QueryResult qr = twitter.search(query); List<Status> tweets = qr.getTweets(); for (int i = 1; i < numberOfPages; i++) { if (!qr.hasNext()) { break; } qr = twitter.search(qr.nextQuery()); tweets.addAll(qr.getTweets()); } if (te.getProperties().isFilterOld()) { for (Status t : tweets) { checkLastId(t.getId()); } } return tweets; }
From source file:org.apache.camel.component.twitter.consumer.timeline.HomeConsumer.java
License:Apache License
public List<Status> pollConsume() throws TwitterException { List<Status> list = te.getProperties().getTwitter().getHomeTimeline(new Paging(lastId)); for (Status s : list) { checkLastId(s.getId()); }//from ww w. j a v a 2 s . c o m return list; }
From source file:org.apache.camel.component.twitter.consumer.timeline.MentionsConsumer.java
License:Apache License
public List<Status> pollConsume() throws TwitterException { List<Status> list = te.getProperties().getTwitter().getMentionsTimeline(new Paging(lastId)); for (Status s : list) { checkLastId(s.getId()); }// w w w.ja v a2s . co m return list; }
From source file:org.apache.camel.component.twitter.consumer.timeline.RetweetsConsumer.java
License:Apache License
public List<Status> pollConsume() throws TwitterException { List<Status> list = te.getProperties().getTwitter().getRetweetsOfMe(new Paging(lastId)); for (Status s : list) { checkLastId(s.getId()); }/* www .java 2 s .c om*/ return list; }
From source file:org.apache.camel.component.twitter.consumer.timeline.UserConsumer.java
License:Apache License
public List<Status> pollConsume() throws TwitterException { List<Status> list = te.getProperties().getTwitter().getUserTimeline(te.getProperties().getUser(), new Paging(lastId)); for (Status s : list) { checkLastId(s.getId()); }// w ww . j a v a 2 s .c o m return list; }
From source file:org.apache.camel.component.twitter.producer.SearchProducer.java
License:Apache License
@Override public void process(Exchange exchange) throws Exception { long myLastId = lastId; // KEYWORDS/*ww w. jav a 2 s .c om*/ // keywords from header take precedence String keywords = exchange.getIn().getHeader(TwitterConstants.TWITTER_KEYWORDS, String.class); if (keywords == null) { keywords = te.getProperties().getKeywords(); } if (keywords == null) { throw new CamelExchangeException("No keywords to use for query", exchange); } Query query = new Query(keywords); // filter of older tweets if (te.getProperties().isFilterOld() && myLastId != 0) { query.setSinceId(myLastId); } // language String lang = exchange.getIn().getHeader(TwitterConstants.TWITTER_SEARCH_LANGUAGE, String.class); if (lang == null) { lang = te.getProperties().getLang(); } if (ObjectHelper.isNotEmpty(lang)) { query.setLang(lang); } // number of elemnt per page Integer count = exchange.getIn().getHeader(TwitterConstants.TWITTER_COUNT, Integer.class); if (count == null) { count = te.getProperties().getCount(); } if (ObjectHelper.isNotEmpty(count)) { query.setCount(count); } // number of pages Integer numberOfPages = exchange.getIn().getHeader(TwitterConstants.TWITTER_NUMBER_OF_PAGES, Integer.class); if (numberOfPages == null) { numberOfPages = te.getProperties().getNumberOfPages(); } Twitter twitter = te.getProperties().getTwitter(); log.debug("Searching twitter with keywords: {}", keywords); QueryResult results = twitter.search(query); List<Status> list = results.getTweets(); for (int i = 1; i < numberOfPages; i++) { if (!results.hasNext()) { break; } log.debug("Fetching page"); results = twitter.search(results.nextQuery()); list.addAll(results.getTweets()); } if (te.getProperties().isFilterOld()) { for (Status t : list) { long newId = t.getId(); if (newId > myLastId) { myLastId = newId; } } } exchange.getIn().setBody(list); // update the lastId after finished the processing if (myLastId > lastId) { lastId = myLastId; } }
From source file:org.apache.camel.component.twitter.producer.UserProducer.java
License:Apache License
private Status updateStatus(StatusUpdate status) throws Exception { Status reponse = te.getProperties().getTwitter().updateStatus(status); log.debug("Updated status: {}", status); log.debug("Status id: {}", reponse.getId()); return reponse; }