List of usage examples for twitter4j Status getLang
String getLang();
From source file:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java
License:Apache License
public static void convert(Status status, Struct struct) { struct.put("CreatedAt", status.getCreatedAt()).put("Id", status.getId()).put("Text", status.getText()) .put("Source", status.getSource()).put("Truncated", status.isTruncated()) .put("InReplyToStatusId", status.getInReplyToStatusId()) .put("InReplyToUserId", status.getInReplyToUserId()) .put("InReplyToScreenName", status.getInReplyToScreenName()).put("Favorited", status.isFavorited()) .put("Retweeted", status.isRetweeted()).put("FavoriteCount", status.getFavoriteCount()) .put("Retweet", status.isRetweet()).put("RetweetCount", status.getRetweetCount()) .put("RetweetedByMe", status.isRetweetedByMe()) .put("CurrentUserRetweetId", status.getCurrentUserRetweetId()) .put("PossiblySensitive", status.isPossiblySensitive()).put("Lang", status.getLang()); Struct userStruct;// w ww . ja v a 2 s .com if (null != status.getUser()) { userStruct = new Struct(USER_SCHEMA); convert(status.getUser(), userStruct); } else { userStruct = null; } struct.put("User", userStruct); Struct placeStruct; if (null != status.getPlace()) { placeStruct = new Struct(PLACE_SCHEMA); convert(status.getPlace(), placeStruct); } else { placeStruct = null; } struct.put("Place", placeStruct); Struct geoLocationStruct; if (null != status.getGeoLocation()) { geoLocationStruct = new Struct(GEO_LOCATION_SCHEMA); convert(status.getGeoLocation(), geoLocationStruct); } else { geoLocationStruct = null; } struct.put("GeoLocation", geoLocationStruct); List<Long> contributers = new ArrayList<>(); if (null != status.getContributors()) { for (Long l : status.getContributors()) { contributers.add(l); } } struct.put("Contributors", contributers); List<String> withheldInCountries = new ArrayList<>(); if (null != status.getWithheldInCountries()) { for (String s : status.getWithheldInCountries()) { withheldInCountries.add(s); } } struct.put("WithheldInCountries", withheldInCountries); struct.put("HashtagEntities", convert(status.getHashtagEntities())); struct.put("UserMentionEntities", convert(status.getUserMentionEntities())); struct.put("MediaEntities", convert(status.getMediaEntities())); struct.put("SymbolEntities", convert(status.getSymbolEntities())); struct.put("URLEntities", convert(status.getURLEntities())); }
From source file:com.lbarriosh.sentimentanalyzer.downloads.TweetsDownloader.java
License:Open Source License
public List<Status> downloadTweets(String[] keywords, TwitterLocale locale, int max_results) throws TwitterException { Twitter twitter = this.tf.getInstance(); Query query = new Query(buildQuery(keywords)); QueryResult result;// ww w . j a v a 2s . co m ArrayList<Status> retrieved_tweets = new ArrayList<Status>(); do { result = twitter.search(query); for (Status tweet : result.getTweets()) { if (tweet.getLang().equals(locale.toString())) { retrieved_tweets.add(tweet); // Workaround. There's a bug in // Twitter4j. } if (retrieved_tweets.size() == max_results) break; } } while ((query = result.nextQuery()) != null && retrieved_tweets.size() < max_results); return retrieved_tweets; }
From source file:com.project.shlok.TopicsAnalyzer.TwitterReader.java
/** * onStatus//from ww w . jav a 2 s .c o m * Gets the text from a twitter status and sends it to the interface for processing * @param Status status - the twitter Status object * @return None * */ public void onStatus(Status status) { String language = status.getLang(); if (language.equals("en")) { String text = status.getText(); twitterStreamInterface.onTweetReceived(query, text); } }
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static Map getFieldsMapFromStatus(String queryOwner, String queryName, String queryString, Status status) { if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); Map m = StatusArraysHelper.getUserMentionMap(status); Map newMap = new HashMap(); for (Object key : m.keySet()) { newMap.put(key.toString(), (Long) m.get(key)); }//from w w w .j a v a2 s . c o m Double longitude = null; Double lattitude = null; if (status.getGeoLocation() != null) { longitude = status.getGeoLocation().getLongitude(); lattitude = status.getGeoLocation().getLatitude(); } String place = null; if (status.getPlace() != null) { place = status.getPlace().getFullName(); } boolean isRetweet = status.getRetweetedStatus() != null; Long retweetedId = null; String retweetedText = null; if (isRetweet) { retweetedId = status.getRetweetedStatus().getId(); retweetedText = status.getRetweetedStatus().getText(); } Map<String, Object> result = new HashMap<>(); result.put(QueryResultItemFieldNames.STATUS_ID, status.getId()); result.put(QueryResultItemFieldNames.CREATED_AT, status.getCreatedAt()); result.put(QueryResultItemFieldNames.CURRENT_USER_RETWEET_ID, status.getCurrentUserRetweetId()); result.put(QueryResultItemFieldNames.FAVOURITE_COUNT, status.getFavoriteCount()); result.put(QueryResultItemFieldNames.FAVOURITED, status.isFavorited()); result.put(QueryResultItemFieldNames.HASHTAGS, StatusArraysHelper.getHashTagsList(status)); result.put(QueryResultItemFieldNames.IN_REPLY_TO_SCREEN_NAME, (status.getInReplyToScreenName())); result.put(QueryResultItemFieldNames.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId()); result.put(QueryResultItemFieldNames.IN_REPLY_TO_USER_ID, status.getInReplyToUserId()); result.put(QueryResultItemFieldNames.LATITUDE, lattitude); result.put(QueryResultItemFieldNames.LONGITUDE, longitude); result.put(QueryResultItemFieldNames.MENTIONS, newMap); result.put(QueryResultItemFieldNames.LANGUAGE, status.getLang()); result.put(QueryResultItemFieldNames.PLACE, place); result.put(QueryResultItemFieldNames.POSSIBLY_SENSITIVE, status.isPossiblySensitive()); result.put(QueryResultItemFieldNames.QUERY_NAME, queryName); result.put(QueryResultItemFieldNames.QUERY_OWNER, queryOwner); result.put(QueryResultItemFieldNames.QUERY, queryString); result.put(QueryResultItemFieldNames.RELEVANT_QUERY_TERMS, TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.put(QueryResultItemFieldNames.RETWEET, isRetweet); result.put(QueryResultItemFieldNames.RETWEET_COUNT, status.getRetweetCount()); result.put(QueryResultItemFieldNames.RETWEETED, status.isRetweeted()); result.put(QueryResultItemFieldNames.RETWEETED_BY_ME, status.isRetweetedByMe()); result.put(QueryResultItemFieldNames.RETWEET_STATUS_ID, retweetedId); result.put(QueryResultItemFieldNames.RETWEETED_TEXT, retweetedText); result.put(QueryResultItemFieldNames.SCOPES, StatusArraysHelper.getScopesList(status)); result.put(QueryResultItemFieldNames.SCREEN_NAME, status.getUser().getScreenName()); result.put(QueryResultItemFieldNames.SOURCE, (status.getSource())); result.put(QueryResultItemFieldNames.TEXT, (status.getText())); result.put(QueryResultItemFieldNames.TRUNCATED, status.isTruncated()); result.put(QueryResultItemFieldNames.URLS, StatusArraysHelper.getUrlsList(status)); result.put(QueryResultItemFieldNames.USER_ID, status.getUser().getId()); result.put(QueryResultItemFieldNames.USER_NAME, (status.getUser().getName())); result.put(QueryResultItemFieldNames.USER_DESCRIPTION, (status.getUser().getDescription())); result.put(QueryResultItemFieldNames.USER_LOCATION, (status.getUser().getLocation())); result.put(QueryResultItemFieldNames.USER_URL, (status.getUser().getURL())); result.put(QueryResultItemFieldNames.USER_IS_PROTECTED, status.getUser().isProtected()); result.put(QueryResultItemFieldNames.USER_FOLLOWERS_COUNT, status.getUser().getFollowersCount()); result.put(QueryResultItemFieldNames.USER_CREATED_AT, status.getUser().getCreatedAt()); result.put(QueryResultItemFieldNames.USER_FRIENDS_COUNT, status.getUser().getFriendsCount()); result.put(QueryResultItemFieldNames.USER_LISTED_COUNT, status.getUser().getListedCount()); result.put(QueryResultItemFieldNames.USER_STATUSES_COUNT, status.getUser().getStatusesCount()); result.put(QueryResultItemFieldNames.USER_FAVOURITES_COUNT, status.getUser().getFavouritesCount()); return result; }
From source file:com.raythos.sentilexo.twitter.domain.QueryResultItemMapper.java
License:Apache License
public static TwitterQueryResultItemAvro mapItem(String queryOwner, String queryName, String queryString, Status status) { TwitterQueryResultItemAvro result = new TwitterQueryResultItemAvro(); if (queryName != null) queryName = queryName.toLowerCase(); if (queryOwner != null) queryOwner = queryOwner.toLowerCase(); result.setQueryName(queryName);/*from w ww . ja va 2 s . co m*/ result.setQueryOwner(queryOwner); result.setQuery(queryString); result.setStatusId(status.getId()); result.setText(status.getText()); result.setRelevantQueryTerms(TwitterUtils.relevantQueryTermsFromStatus(queryString, status)); result.setLang(status.getLang()); result.setCreatedAt(status.getCreatedAt().getTime()); User user = status.getUser(); result.setUserId(user.getId()); result.setScreenName(user.getScreenName()); result.setUserLocation(user.getLocation()); result.setUserName(user.getName()); result.setUserDescription(user.getDescription()); result.setUserIsProtected(user.isProtected()); result.setUserFollowersCount(user.getFollowersCount()); result.setUserCreatedAt(user.getCreatedAt().getTime()); result.setUserCreatedAtAsString(DateTimeUtils.getDateAsText(user.getCreatedAt())); result.setCreatedAtAsString(DateTimeUtils.getDateAsText(status.getCreatedAt())); result.setUserFriendsCount(user.getFriendsCount()); result.setUserListedCount(user.getListedCount()); result.setUserStatusesCount(user.getStatusesCount()); result.setUserFavoritesCount(user.getFavouritesCount()); result.setCurrentUserRetweetId(status.getCurrentUserRetweetId()); result.setInReplyToScreenName(status.getInReplyToScreenName()); result.setInReplyToStatusId(status.getInReplyToStatusId()); result.setInReplyToUserId(status.getInReplyToUserId()); if (status.getGeoLocation() != null) { result.setLatitude(status.getGeoLocation().getLatitude()); result.setLongitude(status.getGeoLocation().getLongitude()); } result.setSource(status.getSource()); result.setTrucated(status.isTruncated()); result.setPossiblySensitive(status.isPossiblySensitive()); result.setRetweet(status.getRetweetedStatus() != null); if (result.getRetweet()) { result.setRetweetStatusId(status.getRetweetedStatus().getId()); result.setRetweetedText(status.getRetweetedStatus().getText()); } result.setRetweeted(status.isRetweeted()); result.setRetweetCount(status.getRetweetCount()); result.setRetweetedByMe(status.isRetweetedByMe()); result.setFavoriteCount(status.getFavoriteCount()); result.setFavourited(status.isFavorited()); if (status.getPlace() != null) { result.setPlace(status.getPlace().getFullName()); } Scopes scopesObj = status.getScopes(); if (scopesObj != null) { List scopes = Arrays.asList(scopesObj.getPlaceIds()); result.setScopes(scopes); } return result; }
From source file:de.twitterlivesearch.filter.LanguageFilter.java
License:Apache License
@Override public boolean tweetMatches(Status tweet) { if (tweet.getLang() == "DE" || tweet.getLang() == "EN") { return true; }/*from w ww .j a va 2 s.c o m*/ return false; }
From source file:de.twitterlivesearch.twitter.TwitterStreamListener.java
License:Apache License
@Override public void onStatus(Status status) { if (log.isTraceEnabled()) { log.trace("Incoming Tweet: " + status.getText()); }/*from w ww . j av a2 s . c o m*/ String textForDoc = StringUtils.join(Tokenizer.getTokensForString(status.getText(), status.getLang()), AnalyzerMapping.getInstance().TOKEN_DELIMITER); // in case the document is empty after tokenizing (i.e. just stopwords) // we shouldnt add it to the index... if (textForDoc.isEmpty()) { return; } Document doc = new Document(); Integer id = IdGenerator.getInstance().getNextId(); // updating the tweet holder which holds all tweet objects try { tweetHolder.getTweets().set(id, status); } catch (IndexOutOfBoundsException e) { tweetHolder.getTweets().add(status); } // adding a new document to the lucene index, text the tweets message // and gets tokenized doc.add(new IntField(FieldNames.ID.getField(), id, Field.Store.YES)); if (log.isTraceEnabled()) { log.trace("Indexing Document: " + textForDoc); } doc.add(new Field(FieldNames.TEXT.getField(), textForDoc, TextField.TYPE_NOT_STORED)); try { // deleting the oldest document iwriter.deleteDocuments(NumericRangeQuery.newIntRange(FieldNames.ID.getField(), id, id, true, true)); // writing the new document iwriter.addDocument(doc); } catch (IOException e) { log.fatal("Error when writing or deleting from the index!", e); } try { iwriter.commit(); } catch (IOException e) { log.fatal("Error when trying to commit to index!", e); } // iterating through all the queries in the queryHolder to see if the // added tweet matches any existing query for (String queryString : QueryManager.getInstance().getQueries()) { List<Document> hits = searcher.searchForTweets(id, queryString); if (hits.size() > 1) { IllegalStateException e = new IllegalStateException( "The query with string " + queryString + " and id " + id + " returned " + hits.size() + " documents. This can only happen if id is not unique!"); log.fatal("Error when searching", e); } for (Document document : hits) { // invoking every action listener registered for the given query // with every document (must actually be a single result, // because id must be unique!) for (QueryWrapper qw : QueryManager.getInstance().getQueryWrappersForQuery(queryString)) { Status tweet = tweetHolder.getTweet(document.get(FieldNames.ID.getField())); if (FilterManager.tweetMatchesFilter(tweet, qw.getFilter())) { qw.getListener().handleNewTweet(tweet); if (log.isTraceEnabled()) { log.trace("Informed Listener " + qw.getListener() + " that new tweet is incoming: " + queryString + " (tokenized)"); } } } } } }
From source file:gh.polyu.user.TrackUsers.java
License:Apache License
public void track(final int no, final int p) { final TwitterDBHandle handle = new TwitterDBHandle(); handle.intialTwitterDBhandle();//from ww w. ja va 2 s . co m while (alive) { alive = false; StatusListener listener = new StatusListener() { ArrayList<_TweetLink> listlink = new ArrayList<_TweetLink>(); int cnt = 0; String oldmonth = "20138"; String table = "UserTweet20138"; String oldday = ""; String currentday = ""; String currentmonth = ""; long lastinsert = 0l; long nowinsert = 0l; int newday = 0; String newtime = ""; @Override public void onStatus(Status status) { if (status.getId() == 123 && status.getText().equals("YOU are WORNG!.")) { System.out.println("Connection Need to be rebuilt!!"); alive = true; } else if (status.getLang().equals("en")) { _TweetLink tweet = new _TweetLink(); String Test = status.getText(); tweet.setText(Test); Date time = status.getCreatedAt(); tweet.setTime(time); tweet.setUserName(status.getUser().getName()); HashtagEntity[] hashtagentity = status.getHashtagEntities(); StringBuffer hashen = new StringBuffer(); for (int i = 0; i < hashtagentity.length; i++) { hashen.append(hashtagentity[i].getText()); hashen.append(";"); } tweet.setHashtag(hashen.toString()); URLEntity[] URLEn = status.getURLEntities(); StringBuffer URL = new StringBuffer(); for (int i = 0; i < URLEn.length; i++) { URL.append(URLEn[i].getURL()); URL.append(";"); } tweet.setURL(URL.toString()); //user mention UserMentionEntity[] userEn = status.getUserMentionEntities(); StringBuffer mentuser = new StringBuffer(); for (int i = 0; i < userEn.length; i++) { mentuser.append(userEn[i].getId()); mentuser.append(";"); } tweet.setUerMention(mentuser.toString()); //if(mentuser.length()!=0); //System.out.println("mentuser: "+ mentuser); //tweetID tweet.setTweetID(status.getId()); //if(ID!=null) // original twitterID tweet.setOriginID(status.getInReplyToStatusId()); //original user ID tweet.setOriginUser(status.getInReplyToUserId()); // user ID User users = status.getUser(); tweet.setTweetUser(users.getId()); //places Place Pl = status.getPlace(); String place = ""; if (Pl != null) { place = Pl.getFullName(); //System.out.println("place "+place); } tweet.setPlace(place); // Retweetcoun long num = 0; if (status.getRetweetedStatus() != null) { num = status.getRetweetedStatus().getRetweetCount(); //System.out.println("retweetcount"+num); tweet.setRetweetCount(num); tweet.setRetweet(1); } else { tweet.setRetweetCount(0); tweet.setRetweet(0); } // if(Retweet!=null) //System.out.println("Retweetcount: "+ Retweet); //isfavourate boolean favourate = status.isFavorited(); /*if(favourate) { fav = 1; tweet.setFavourate(fav); fav =0; System.out.println("isf "+ fav); }*/ // is retweet //String other = status.toString(); // tweet.setOther(other); listlink.add(tweet); Calendar cal = Calendar.getInstance(); int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH) + 1; int day = cal.get(Calendar.DAY_OF_MONTH); currentmonth = String.valueOf(year) + String.valueOf(month); currentday = String.valueOf(day); if (currentmonth.equals(oldmonth)) { if (currentday.equals(oldday)) ; else { newday = 1; SimpleDateFormat formatter = new SimpleDateFormat("MMddHH:mm:ss "); Date curDate = new Date(System.currentTimeMillis());// newtime = formatter.format(curDate); } } else { try { handle.database_connection(); table = "UserTweet" + String.valueOf(year) + String.valueOf(month); System.out.println("create new table " + table); String CREATE_TABLE = "create table " + table + "(TweetID varchar(100), UserName varchar(200), TwitterUser varchar(145), OriginID varchar(100), OriginUser varchar(100), place varchar(100), RetweetCount varchar(100), isRetweet int(5), Text varchar(500), Time datetime," + "Hashtag varchar(200), URL varchar(200), UerMention varchar(200))"; Statement st = handle.conn.createStatement(); st.execute(CREATE_TABLE); String Create_Index = "alter table " + table + " add index time (Time)"; st.execute(Create_Index); String Create_Index2 = "alter table " + table + " add index userID (TwitterUser)"; st.execute(Create_Index2); String key = "ALTER TABLE " + table + " ADD PRIMARY KEY (TweetID)"; st.execute(key); } catch (SQLException e) { e.printStackTrace(); } handle.close_databasehandle(); try { TwitterDBHandle handle2 = new TwitterDBHandle(); handle2.intialTwitterDBhandle2(); handle2.database_connection(); table = "UserTweet" + String.valueOf(year) + String.valueOf(month); System.out.println("create new table " + table); String CREATE_TABLE = "create table " + table + "(TweetID varchar(100), UserName varchar(200), TwitterUser varchar(145), OriginID varchar(100), OriginUser varchar(100), place varchar(100), RetweetCount varchar(100), isRetweet int(5), Text varchar(500), Time datetime," + "Hashtag varchar(200), URL varchar(200), UerMention varchar(200))"; Statement st = handle2.conn.createStatement(); st.execute(CREATE_TABLE); String Create_Index = "alter table " + table + " add index time (Time)"; st.execute(Create_Index); String Create_Index2 = "alter table " + table + " add index userID (TwitterUser)"; st.execute(Create_Index2); String key = "ALTER TABLE " + table + " ADD PRIMARY KEY (TweetID)"; st.execute(key); handle2.close_databasehandle(); } catch (SQLException e) { e.printStackTrace(); } } //System.out.println("OTHER: "+ other); if ((cnt++) % 1000 == 0) { if (newday == 1) { newday = 0; oldday = currentday; GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); gs.send("THREAD" + p + " :" + "program no" + no + "message" + newtime, "I am still alive"); newtime = ""; } try { handle.database_connection(); handle.userTweet(table, listlink); nowinsert = System.currentTimeMillis(); System.err.println( "No: " + no + "program " + "totally " + cnt + " tweets downloaded!\n" + new Date(nowinsert) + " " + new Date(lastinsert)); lastinsert = nowinsert; nowinsert = 0l; handle.close_databasehandle(); } catch (SQLException e) { handle.close_databasehandle(); e.printStackTrace(); // TODO Auto-generated catch block TwitterDBHandle handle2 = new TwitterDBHandle(); handle2.intialTwitterDBhandle2(); handle2.database_connection(); try { handle2.userTweet(table, listlink); nowinsert = System.currentTimeMillis(); System.err.println("New Database No: " + no + "program " + "totally " + cnt + " tweets downloaded!\n" + new Date(nowinsert) + new Date(lastinsert)); lastinsert = nowinsert; nowinsert = 0l; handle2.close_databasehandle(); } catch (SQLException e1) { // TODO Auto-generated catch block GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); try { gs.SendSSLMessage("cscchenyoyo@gmail.com", "program error", "both databases are down"); } catch (MessagingException ee) { // TODO Auto-generated catch block e.printStackTrace(); } } GmailSend gs = new GmailSend("cscchenyoyo@gmail.com", "910316ccy"); try { gs.SendSSLMessage("cscchenyoyo@gmail.com", "program error", "change database to another one"); } catch (MessagingException ee) { // TODO Auto-generated catch block e.printStackTrace(); } } listlink.clear(); } } } @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(); } }; TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); twitterOAuth twtOauth = new twitterOAuth(); twtOauth.AuthoritywithS(twitterStream, key); twitterStream.addListener(listener); twitterStream.filter(new FilterQuery(0, follow)); /* try { Thread.sleep(3000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); }*/ } }
From source file:im.ligas.twittermap.portlet.TwitterStatusListener.java
License:Open Source License
@Override public void onStatus(Status status) { Place place = status.getPlace();// ww w.ja va2s. co m if (place != null) { String iso3Country = new Locale(status.getLang(), status.getPlace().getCountryCode()).getISO3Country(); JSONObject json = JSONFactoryUtil.createJSONObject(); json.put("country", iso3Country); GeoLocation[][] coordinates = place.getBoundingBoxCoordinates(); GeoLocation location = coordinates[0][0]; json.put("lat", location.getLatitude()); json.put("lng", location.getLongitude()); LOG.debug(json); broadcast(json.toString()); } }
From source file:info.maslowis.twitterripper.util.Util.java
License:Open Source License
/** * Returns a representation the status (tweet) as string * * @return a representation the status as string in format <em>Status{id=, text='', lang='', createdAt=, geoLocation=, isFavorited=, isRetweeted=, retweetCount=, isTruncated=}</em> *//* w ww . j a v a 2s .c o m*/ public static String toString(final Status status) { return "Status{id=" + status.getId() + ", text='" + status.getText() + "', lang='" + status.getLang() + "', createdAt=" + status.getCreatedAt() + ", geoLocation=" + status.getGeoLocation() + ", isFavorited=" + status.isFavorited() + ", isRetweeted=" + status.isRetweeted() + ", retweetCount=" + status.getRetweetCount() + ", isTruncated=" + status.isTruncated() + "}"; }