List of usage examples for twitter4j Status getText
String getText();
From source file:org.seasr.meandre.apps.twitter.TwitterToTuple.java
public void onStatus(Status status) { String text = status.getText(); ////from w w w . jav a 2 s . c o m // cull out as much as possible here // text = TwitterServices.convertToASCII(text); if (text == null) { // console.info("SKIP non-ascii " + status.getText()); return; } float pct = TwitterServices.parsingPercentage(text); if (pct < 0.40) { // console.info("SKIP " + pct + " " + text); return; } User user = status.getUser(); String location = TwitterServices.getLocation(status); /* if (location == TwitterServices.NO_LOCATION) { return; } */ //console.info("Raw " + status.getText()); if (status.isRetweet()) { console.fine("YES RT " + status.getText()); } String clean = clean(text); /* if (c.length() != text.length()) { console.info(text); console.info(c); } */ outTuple.setValue(ID_IDX, ID++); outTuple.setValue(USER_IDX, user.getId()); outTuple.setValue(FOLLOWERS_IDX, user.getFavouritesCount()); outTuple.setValue(TWEET_IDX, text); outTuple.setValue(TEXT_IDX, clean); outTuple.setValue(LOCATION_IDX, location); // console.info("got data "); synchronized (buffer) { buffer.add(outTuple.convert()); if (buffer.size() > WINDOW_SIZE) { // console.info("wake the waiter " + buffer.size()); buffer.notifyAll(); } } // console.info("leaving"); }
From source file:org.selman.tweetamo.PersistentStore.java
License:Apache License
private static Map<String, AttributeValue> newItem(Status status) { Map<String, AttributeValue> item = new HashMap<String, AttributeValue>(); item.put(COL_ID, new AttributeValue().withN(Long.toString(status.getId()))); item.put(COL_CREATEDAT, new AttributeValue().withN(Long.toString(status.getCreatedAt().getTime()))); if (status.getGeoLocation() != null) { item.put(COL_LAT, new AttributeValue().withN(Double.toString(status.getGeoLocation().getLatitude()))); item.put(COL_LONG, new AttributeValue().withN(Double.toString(status.getGeoLocation().getLongitude()))); }//from w ww .j a v a 2 s. c om item.put(COL_SCREENNAME, new AttributeValue().withS(status.getUser().getScreenName())); item.put(COL_TEXT, new AttributeValue().withS(status.getText())); return item; }
From source file:org.sintef.jarduino.examples.advanced.Twitter4Arduino.java
License:LGPL
@Override protected void loop() { List<Status> statuses;//from w w w . jav a 2 s . co m try { //Get status updates from your tweet feed statuses = twitter.getFriendsTimeline(); //select the last tweet Status status = (Status) statuses.get(0); //check if it is a new tweet, or if you have it from before if (last == null || !status.getUser().getName().equals(last.getUser().getName()) && !status.getText().equals(last.getText())) { //check that the tweet isn't written by yourself if (!status.getUser().getScreenName().equalsIgnoreCase(userName)) { System.out.println(status.getUser().getScreenName() + ":" + status.getText()); last = status; //light up the Arduino digitalWrite(led, DigitalState.HIGH); timer.schedule(new Timeout(this), 10000); } } //wait ten seconds before checking again //Twitter have a limit on how many times you can check per day delay(10000); } catch (TwitterException e) { e.printStackTrace(); } }
From source file:org.smarttechie.servlet.SimpleStream.java
public void getStream(TwitterStream twitterStream, String[] parametros, final Session session)//,PrintStream out) { listener = new StatusListener() { @Override/* ww w.j a va 2s . c o m*/ public void onException(Exception arg0) { // TODO Auto-generated method stub } @Override public void onDeletionNotice(StatusDeletionNotice arg0) { // TODO Auto-generated method stub } @Override public void onScrubGeo(long arg0, long arg1) { // TODO Auto-generated method stub } @Override public void onStatus(Status status) { Twitter twitter = new TwitterFactory().getInstance(); User user = status.getUser(); // gets Username String username = status.getUser().getScreenName(); System.out.println(""); String profileLocation = user.getLocation(); System.out.println(profileLocation); long tweetId = status.getId(); System.out.println(tweetId); String content = status.getText(); System.out.println(content + "\n"); JSONObject obj = new JSONObject(); obj.put("User", status.getUser().getScreenName()); obj.put("ProfileLocation", user.getLocation().replaceAll("'", "''")); obj.put("Id", status.getId()); obj.put("UserId", status.getUser().getId()); //obj.put("User", status.getUser()); obj.put("Message", status.getText().replaceAll("'", "''")); obj.put("CreatedAt", status.getCreatedAt().toString()); obj.put("CurrentUserRetweetId", status.getCurrentUserRetweetId()); //Get user retweeteed String otheruser; try { if (status.getCurrentUserRetweetId() != -1) { User user2 = twitter.showUser(status.getCurrentUserRetweetId()); otheruser = user2.getScreenName(); System.out.println("Other user: " + otheruser); } } catch (Exception ex) { System.out.println("ERROR: " + ex.getMessage().toString()); } obj.put("IsRetweet", status.isRetweet()); obj.put("IsRetweeted", status.isRetweeted()); obj.put("IsFavorited", status.isFavorited()); obj.put("InReplyToUserId", status.getInReplyToUserId()); //In reply to obj.put("InReplyToScreenName", status.getInReplyToScreenName()); obj.put("RetweetCount", status.getRetweetCount()); if (status.getGeoLocation() != null) { obj.put("GeoLocationLatitude", status.getGeoLocation().getLatitude()); obj.put("GeoLocationLongitude", status.getGeoLocation().getLongitude()); } JSONArray listHashtags = new JSONArray(); String hashtags = ""; for (HashtagEntity entity : status.getHashtagEntities()) { listHashtags.add(entity.getText()); hashtags += entity.getText() + ","; } if (!hashtags.isEmpty()) obj.put("HashtagEntities", hashtags.substring(0, hashtags.length() - 1)); if (status.getPlace() != null) { obj.put("PlaceCountry", status.getPlace().getCountry()); obj.put("PlaceFullName", status.getPlace().getFullName()); } obj.put("Source", status.getSource()); obj.put("IsPossiblySensitive", status.isPossiblySensitive()); obj.put("IsTruncated", status.isTruncated()); if (status.getScopes() != null) { JSONArray listScopes = new JSONArray(); String scopes = ""; for (String scope : status.getScopes().getPlaceIds()) { listScopes.add(scope); scopes += scope + ","; } if (!scopes.isEmpty()) obj.put("Scopes", scopes.substring(0, scopes.length() - 1)); } obj.put("QuotedStatusId", status.getQuotedStatusId()); JSONArray list = new JSONArray(); String contributors = ""; for (long id : status.getContributors()) { list.add(id); contributors += id + ","; } if (!contributors.isEmpty()) obj.put("Contributors", contributors.substring(0, contributors.length() - 1)); System.out.println("" + obj.toJSONString()); insertNodeNeo4j(obj); //out.println(obj.toJSONString()); String statement = "INSERT INTO TweetsClassification JSON '" + obj.toJSONString() + "';"; executeQuery(session, statement); } @Override public void onTrackLimitationNotice(int arg0) { // TODO Auto-generated method stub } @Override public void onStallWarning(StallWarning sw) { throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. } }; FilterQuery fq = new FilterQuery(); fq.track(parametros); twitterStream.addListener(listener); twitterStream.filter(fq); }
From source file:org.socialsketch.tool.rubbish.experiments.PrintSampleStream.java
License:Apache License
/** * Main entry of this application.// w w w .j a v a2 s . com * * @param args */ public static void main(String[] args) throws TwitterException { TwitterStream twitterStream = new TwitterStreamFactory().getInstance(); StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @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.addListener(listener); twitterStream.sample(); //twitterStream. }
From source file:org.socialsketch.tool.rubbish.twitterstream.PrintFilterStream.java
License:Apache License
/** * Main entry of this application.//from w ww. j ava2 s .c o m * * @param args follow(comma separated user ids) track(comma separated filter terms) * @throws twitter4j.TwitterException */ public static void main(String[] args) throws TwitterException { // if (args.length < 1) { // System.out.println("Usage: java twitter4j.examples.PrintFilterStream [follow(comma separated numerical user ids)] [track(comma separated filter terms)]"); // System.exit(-1); // } StatusListener listener = new StatusListener() { @Override public void onStatus(Status status) { System.out.println("@" + status.getUser().getScreenName() + " - " + status.getText()); } @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(); twitterStream.addListener(listener); ArrayList<Long> follow = new ArrayList<Long>(); ArrayList<String> track = new ArrayList<String>(); // for (String arg : args) { // if (isNumericalArgument(arg)) { // for (String id : arg.split(",")) { // follow.add(Long.parseLong(id)); // } // } else { // track.addAll(Arrays.asList(arg.split(","))); // } // } track.add("void setup draw"); track.add("void size"); long[] followArray = new long[follow.size()]; for (int i = 0; i < follow.size(); i++) { followArray[i] = follow.get(i); } String[] trackArray = track.toArray(new String[track.size()]); // filter() method internally creates a thread which manipulates TwitterStream and calls these adequate listener methods continuously. twitterStream.filter(new FilterQuery(0, followArray, trackArray)); }
From source file:org.sociotech.communitymashup.source.twitter.TwitterSourceService.java
License:Open Source License
/** * Creates a content for the given tweet, adds it to the data set and sets * the author.// w w w. java 2s. c o m * * @param author * Person corresponding to the twitter user which authored the * tweet * @param tweet * The tweet * @return The Content created from the tweet, null in error case. */ private Content createContentFromTweet(Person author, Status tweet) { if (tweet == null) { return null; } String tweetText = tweet.getText(); if (tweetText == null || tweetText.isEmpty()) { return null; } String ident = tweet.getId() + ""; if (this.getContentWithSourceIdent(ident) != null) { // status already created return null; } Content tweetContent = factory.createContent(); tweetContent.setStringValue(tweetText); tweetContent.setName(createTitleFromTwitterText(tweetText)); tweetContent = (Content) this.add(tweetContent, ident); if (tweetContent == null) { return null; } tweetContent.metaTag(TwitterTags.TWITTER); tweetContent.setCreated(tweet.getCreatedAt()); if (author != null) { tweetContent.setAuthor(author); } // and tag the status HashtagEntity[] hashtags = tweet.getHashtagEntities(); tagIOwithHashtags(tweetContent, hashtags); UserMentionEntity[] mentionedUsers = tweet.getUserMentionEntities(); if (mentionedUsers != null && mentionedUsers.length > 0 && source.isPropertyTrue(TwitterProperties.ADD_MENTIONED_PEOPLE_PROPERTY)) { for (int i = 0; i < mentionedUsers.length; i++) { Person mentionedPerson = getPersonForTwitterUserId(mentionedUsers[i].getId()); if (mentionedPerson == null) { continue; } tweetContent.addContributor(mentionedPerson); } } URLEntity[] urlEntities = tweet.getURLEntities(); if (urlEntities != null && urlEntities.length > 0 && source.isPropertyTrue(TwitterProperties.ADD_URL_ENTITIES_PROPERTY)) { for (int i = 0; i < urlEntities.length; i++) { String url = urlEntities[i].getURL(); if (url != null) { // attach url as website tweetContent.addWebSite(url); } } } // no more available // String language = tweet.getIsoLanguageCode(); // if(language != null && !language.isEmpty()) // { // // set in content // tweetContent.setLocale(language); // // set as meta tag // tweetContent.metaTag(language); // } // TODO check media entities // MediaEntity[] mediaEntities = twitterStatus.getMediaEntities(); // add location GeoLocation tweetLocation = tweet.getGeoLocation(); Place place = tweet.getPlace(); if (tweetLocation != null || place != null) { Location location = factory.createLocation(); if (place != null) { location.setStreet(place.getStreetAddress()); location.setCountry(place.getCountry()); location.setStringValue(place.getFullName()); } if (tweetLocation != null) { location.setLatitude(tweetLocation.getLatitude() + ""); location.setLongitude(tweetLocation.getLongitude() + ""); } location = (Location) this.add(location, "tloc_" + tweet.getId()); if (location != null) { location.metaTag(TwitterTags.TWITTER); tweetContent.extend(location); if (place != null) { location.metaTag(place.getCountryCode()); location.metaTag(place.getPlaceType()); } } } return tweetContent; }
From source file:org.sonar.plugins.twitter.TwitterPublisher.java
License:Open Source License
protected void updateStatus(String message) throws TwitterException { LOG.info("Updating Twitter status to: '{}'", message); Status status = twitter.updateStatus(message); LOG.info("Successfully updated the status to [" + status.getText() + "]."); }
From source file:org.talend.spark.utils.twitter.TwitterUtil.java
License:Open Source License
public static Object parse(TwitterParameter parameter, Status status) { if (parameter == TwitterParameter.USERNAME) { return status.getUser().getName(); } else if (parameter == TwitterParameter.TEXT) { return status.getText(); } else if (parameter == TwitterParameter.SOURCE) { return status.getSource(); } else if (parameter == TwitterParameter.ACCESSLEVEL) { return status.getAccessLevel(); } else if (parameter == TwitterParameter.DATE) { return status.getCreatedAt(); } else if (parameter == TwitterParameter.ID) { return status.getId(); } else if (parameter == TwitterParameter.GEOLOCATION_LATITUDE) { return status.getGeoLocation().getLatitude(); } else if (parameter == TwitterParameter.GEOLOCATION_LONGITUDE) { return status.getGeoLocation().getLongitude(); } else if (parameter == TwitterParameter.HASHTAG) { String hashTags = ""; HashtagEntity[] hashTagArray = status.getHashtagEntities(); for (int i = 0; i < hashTagArray.length; i++) { if (hashTags.equals("")) { hashTags = hashTagArray[i].getText(); } else { hashTags = hashTags + "," + hashTagArray[i].getText(); }//from w w w . j ava 2 s . c om } return hashTags; } return null; }
From source file:org.todoke.countstream.Callback.java
License:Apache License
public void increment(Status status) { logger.info("got: " + status.toString()); increment(status.getText(), status.getCreatedAt()); }