Example usage for twitter4j Status getPlace

List of usage examples for twitter4j Status getPlace

Introduction

In this page you can find the example usage for twitter4j Status getPlace.

Prototype

Place getPlace();

Source Link

Document

Returns the place attached to this status

Usage

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.  j  a v a2 s .  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:br.com.porcelli.hornetq.integration.twitter.support.TweetMessageConverterSupport.java

License:Apache License

public static ServerMessage buildMessage(final String queueName, final Status status) {
    final ServerMessage msg = new ServerMessageImpl(status.getId(),
            InternalTwitterConstants.INITIAL_MESSAGE_BUFFER_SIZE);
    msg.setAddress(new SimpleString(queueName));
    msg.setDurable(true);/*  ww  w.j  a v  a2 s  .co m*/

    msg.putStringProperty(TwitterConstants.KEY_MSG_TYPE, MessageType.TWEET.toString());
    msg.putStringProperty(TwitterConstants.KEY_CREATED_AT, read(status.getCreatedAt()));
    msg.putStringProperty(TwitterConstants.KEY_ID, read(status.getId()));

    msg.putStringProperty(TwitterConstants.KEY_TEXT, read(status.getText()));
    msg.putStringProperty(TwitterConstants.KEY_SOURCE, read(status.getSource()));
    msg.putStringProperty(TwitterConstants.KEY_TRUNCATED, read(status.isTruncated()));
    msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_STATUS_ID, read(status.getInReplyToStatusId()));
    msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_USER_ID, read(status.getInReplyToUserId()));
    msg.putStringProperty(TwitterConstants.KEY_IN_REPLY_TO_SCREEN_NAME, read(status.getInReplyToScreenName()));

    msg.putStringProperty(TwitterConstants.KEY_RETWEET, read(status.isRetweet()));
    msg.putStringProperty(TwitterConstants.KEY_FAVORITED, read(status.isFavorited()));

    msg.putStringProperty(TwitterConstants.KEY_ENTITIES_URLS_JSON, read(status.getURLEntities()));
    msg.putStringProperty(TwitterConstants.KEY_ENTITIES_HASHTAGS_JSON, read(status.getHashtagEntities()));
    msg.putStringProperty(TwitterConstants.KEY_ENTITIES_MENTIONS_JSON, read(status.getUserMentionEntities()));

    msg.putStringProperty(TwitterConstants.KEY_CONTRIBUTORS_JSON, read(status.getContributors()));

    if (status.getUser() != null) {
        buildUserData("", status.getUser(), msg);
    }

    GeoLocation gl;
    if ((gl = status.getGeoLocation()) != null) {
        msg.putStringProperty(TwitterConstants.KEY_GEO_LATITUDE, read(gl.getLatitude()));
        msg.putStringProperty(TwitterConstants.KEY_GEO_LONGITUDE, read(gl.getLongitude()));
    }

    Place place;
    if ((place = status.getPlace()) != null) {
        msg.putStringProperty(TwitterConstants.KEY_PLACE_ID, read(place.getId()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_URL, read(place.getURL()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_NAME, read(place.getName()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_FULL_NAME, read(place.getFullName()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_COUNTRY_CODE, read(place.getCountryCode()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_COUNTRY, read(place.getCountry()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_STREET_ADDRESS, read(place.getStreetAddress()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_TYPE, read(place.getPlaceType()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_GEO_TYPE, read(place.getGeometryType()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_TYPE, read(place.getBoundingBoxType()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_COORDINATES_JSON,
                read(place.getBoundingBoxCoordinates().toString()));
        msg.putStringProperty(TwitterConstants.KEY_PLACE_BOUNDING_BOX_GEOMETRY_COORDINATES_JSON,
                read(place.getGeometryCoordinates().toString()));
    }

    msg.putStringProperty(TwitterConstants.KEY_RAW_JSON, status.toString());

    return msg;
}

From source file:ch.schrimpf.core.TwitterCrawler.java

License:Open Source License

/**
 * Performs a single crawl step according to the previous initialized query
 * until the specified limit is reached. Received tweets are stored in the
 * *.csv specified in the easyTwitterCrawler.properties file.
 * <p/>//from w ww . java  2  s  .co  m
 * TODO make selecting values flexible
 *
 * @param limit to stop on
 */
public void crwal(int limit) {
    LOG.info("receiving tweets...");
    int i = 0;
    while (i < limit && running) {
        try {
            QueryResult res = twitter.search(query);
            if (res.getMaxId() > last) {
                for (Status status : res.getTweets()) {
                    String[] line = { String.valueOf(status.getId()), String.valueOf(status.getCreatedAt()),
                            status.getText(), String.valueOf(status.getUser()),
                            String.valueOf(status.getPlace()), status.getLang() };
                    csv.writeResult(Arrays.asList(line));
                    i++;
                }
                last = res.getMaxId();
            } else {
                break;
            }
        } catch (TwitterException e) {
            LOG.warning("could not process tweets");
        }
    }
    tweets += i;
    LOG.info(i + " tweets received in this crawl");
    LOG.info("totally " + tweets + " received");
}

From source file:ColourUs.Trending.java

public boolean validate(Status stat) {
    for (int i = 0; i < size; i++) {
        if (stat.getPlace().getCountry().equals(countries[i])) {
            return true;
        }/*ww w  .  j  a v a2 s .  co m*/
    }
    return false;
}

From source file:com.ebay.pulsar.twittersample.channel.TwitterSampleChannel.java

License:GNU General Public License

@Override
public void open() throws EventException {
    super.open();
    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(false);/* w ww  .  j  av a 2  s.c o m*/

    twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
    StatusListener listener = new StatusListener() {
        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
        }

        @Override
        public void onStallWarning(StallWarning warning) {
        }

        @Override
        public void onStatus(Status status) {
            HashtagEntity[] hashtagEntities = status.getHashtagEntities();

            JetstreamEvent event = new JetstreamEvent();
            event.setEventType("TwitterSample");

            Place place = status.getPlace();
            if (place != null) {
                event.put("country", place.getCountry());
            }
            event.put("ct", status.getCreatedAt().getTime());
            event.put("text", status.getText());
            event.put("lang", status.getLang());
            event.put("user", status.getUser().getName());
            if (hashtagEntities != null && hashtagEntities.length > 0) {
                StringBuilder s = new StringBuilder();
                s.append(hashtagEntities[0].getText());

                for (int i = 1; i < hashtagEntities.length; i++) {
                    s.append(",");
                    s.append(hashtagEntities[i].getText());
                }

                event.put("hashtag", s.toString());
            }

            fireSendEvent(event);
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }
    };
    twitterStream.addListener(listener);
    twitterStream.sample();
}

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;//from w  w  w. j a v a  2  s .  c  om
    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.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  ww. j a va  2 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 .j a  va2s.c o  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:com.wso2.stream.connector.protocol.TweetContent.java

License:Open Source License

public OMElement createBodyContent(OMFactory omFactory, Status status) {
    OMElement tweet = omFactory.createOMElement(qTweet);

    OMElement text = omFactory.createOMElement(qText);
    tweet.addChild(text);//from ww  w  .ja v a 2s. co  m
    text.addChild(omFactory.createOMText(status.getText()));

    OMElement createdAt = omFactory.createOMElement(qCreatedAt);
    tweet.addChild(createdAt);
    createdAt.addChild(omFactory.createOMText(status.getCreatedAt().toString()));

    OMElement latitude = omFactory.createOMElement(qLatitude);
    tweet.addChild(latitude);
    OMElement longitude = omFactory.createOMElement(qLongitude);
    tweet.addChild(longitude);
    if (status.getGeoLocation() != null) {
        latitude.addChild(omFactory.createOMText(String.valueOf(status.getGeoLocation().getLatitude())));
        longitude.addChild(omFactory.createOMText(String.valueOf(status.getGeoLocation().getLongitude())));
    }

    OMElement country = omFactory.createOMElement(qCountry);
    tweet.addChild(country);
    OMElement countryCode = omFactory.createOMElement(qCountryCode);
    tweet.addChild(countryCode);

    if (status.getPlace() != null) {
        country.addChild(omFactory.createOMText(status.getPlace().getCountry()));
        countryCode.addChild(omFactory.createOMText(status.getPlace().getCountryCode()));
    }

    OMElement location = omFactory.createOMElement(qLocation);
    tweet.addChild(location);
    if (status.getUser() != null) {
        location.addChild(omFactory.createOMText(status.getUser().getLocation()));
    }

    OMElement hashTags = omFactory.createOMElement(qHasTags);
    tweet.addChild(hashTags);

    if (status.getHashtagEntities().length > 0) {
        String tags = "";
        for (HashtagEntity h : status.getHashtagEntities()) {
            tags += h.getText() + ";";
        }
        tags = tags.substring(0, tags.length() - 1);
        hashTags.addChild(omFactory.createOMText(tags));
    }

    return tweet;

}

From source file:crawler.DataStorage.java

License:Apache License

private static void sqlStore(Status status) throws SQLException {
    long sql_pid = Settings.pid;
    Settings.pid++;/*from  ww w .  j a v  a  2s  .c o m*/

    SimpleDateFormat tempDate = new SimpleDateFormat("yyyy-MM-dd, HH:mm:ss, z");
    String sqlCreateAt = tempDate.format(new java.util.Date(status.getCreatedAt().getTime()));

    double sqlGeoLocationLat = 0;
    double sqlGeoLocationLong = 0;

    if (status.getGeoLocation() != null) {
        sqlGeoLocationLat = status.getGeoLocation().getLatitude();
        sqlGeoLocationLong = status.getGeoLocation().getLongitude();
    }

    String sqlPlace = (status.getPlace() != null ? status.getPlace().getFullName() : "");
    long sqlId = status.getId();
    String sqlTweet = status.getText().replace("'", "''");
    String sqlSource = status.getSource().replace("'", "''");
    sqlSource = sqlSource.replace("\\", "\\\\");
    String sqlLang = status.getUser().getLang();
    String sqlScreenName = status.getUser().getScreenName();
    String sqlReplyTo = status.getInReplyToScreenName();
    long sqlRtCount = status.getRetweetCount();

    HashtagEntity[] hashs = status.getHashtagEntities();
    String sqlHashtags = "";
    for (HashtagEntity hash : hashs)
        sqlHashtags += hash.getText() + " ";

    pstm.setLong(1, sql_pid);
    pstm.setString(2, sqlCreateAt);
    pstm.setDouble(3, sqlGeoLocationLat);
    pstm.setDouble(4, sqlGeoLocationLong);
    pstm.setString(5, sqlPlace);
    pstm.setLong(6, sqlId);
    pstm.setString(7, sqlTweet);
    pstm.setString(8, sqlSource);
    pstm.setString(9, sqlLang);
    pstm.setString(10, sqlScreenName);
    pstm.setString(11, sqlReplyTo);
    pstm.setLong(12, sqlRtCount);
    pstm.setString(13, sqlHashtags);

    pstm.addBatch();
}