Example usage for twitter4j Place getId

List of usage examples for twitter4j Place getId

Introduction

In this page you can find the example usage for twitter4j Place getId.

Prototype

String getId();

Source Link

Usage

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);//from  w w w  .jav a  2  s . c o 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:com.github.jcustenborder.kafka.connect.twitter.StatusConverter.java

License:Apache License

public static void convert(Place place, Struct struct) {
    if (null == place) {
        return;//  www  . jav  a  2s .c om
    }
    struct.put("Name", place.getName()).put("StreetAddress", place.getStreetAddress())
            .put("CountryCode", place.getCountryCode()).put("Id", place.getId())
            .put("Country", place.getCountry()).put("PlaceType", place.getPlaceType())
            .put("URL", place.getURL()).put("FullName", place.getFullName());
}

From source file:DataCollections.PlaceHelper.java

public Place_dbo convertPlacetoPlace_dbo(Place place) {
    Place_dbo placedbo = new Place_dbo();
    placedbo.values[Place_dbo.map.get("place_id")].setValue(place.getId());
    placedbo.values[Place_dbo.map.get("name")].setValue(place.getName());
    placedbo.values[Place_dbo.map.get("full_name")].setValue(place.getFullName());
    placedbo.values[Place_dbo.map.get("country")].setValue(place.getCountry());
    placedbo.values[Place_dbo.map.get("country_code")].setValue(place.getCountryCode());
    placedbo.values[Place_dbo.map.get("place_type")].setValue(place.getPlaceType());
    placedbo.values[Place_dbo.map.get("url")].setValue(place.getURL());
    placedbo.values[Place_dbo.map.get("contained_within_place")]
            .setValue(getAllContainedWithIngPlaces(place.getContainedWithIn()));
    placedbo.values[Place_dbo.map.get("boundingbox_coord")]
            .setValue(stringifyBoundingBoxCoordinates(place.getBoundingBoxCoordinates()));
    double[] centroid = computeCentroid(place.getBoundingBoxCoordinates());
    placedbo.values[Place_dbo.map.get("centroid_lon")].setValue(String.valueOf(centroid[0]));
    placedbo.values[Place_dbo.map.get("centroid_lat")].setValue(String.valueOf(centroid[1]));

    return placedbo;
}

From source file:DataCollections.PlaceHelper.java

public String getAllContainedWithIngPlaces(Place[] places) {

    JSONArray jsonarray = new JSONArray();

    for (Place p : places) {
        JSONObject jobj = new JSONObject();
        jobj.put("id", p.getId());
        jobj.put("n", p.getName());
        jobj.put("pt", p.getPlaceType());
        jsonarray.add(jobj);//from   ww  w.  j  ava2 s.c o  m
    }
    return jsonarray.toJSONString();

}

From source file:geo.GetGeoDetails.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.GetGeoDetails [place id]
 *
 * @param args message// w  w  w  .j a v  a2  s . c o  m
 */
public static void main(String[] args) {
    String s = "939067979a7f3b95";
    try {
        Twitter twitter = new TwitterFactory(Data.getConf().build()).getInstance();
        Place place = twitter.getGeoDetails(s);
        System.out.println("name: " + place.getName());
        System.out.println("country: " + place.getCountry());
        System.out.println("country code: " + place.getCountryCode());
        System.out.println("full name: " + place.getFullName());
        System.out.println("id: " + place.getId());
        System.out.println("place type: " + place.getPlaceType());
        System.out.println("street address: " + place.getStreetAddress());

        Place[] containedWithinArray = place.getContainedWithIn();
        if (containedWithinArray != null && containedWithinArray.length != 0) {
            System.out.println("  contained within:");
            for (Place containedWithinPlace : containedWithinArray) {
                System.out.println("  id: " + containedWithinPlace.getId() + " name: "
                        + containedWithinPlace.getFullName());
            }
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to retrieve geo details: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:geo.GetSimilarPlaces.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.GetSimilarPlaces [latitude] [longitude] [place id]
 *
 * @param args message//from w  w w . ja  v a2 s.com
 */
public static void main(String[] args) {
    if (args.length < 3) {
        System.out.println(
                "Usage: java twitter4j.examples.geo.GetSimilarPlaces [latitude] [longitude] [name] [place id]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        GeoLocation location = new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1]));
        String name = args[2];
        String containedWithin = null;
        if (args.length >= 4) {
            containedWithin = args[3];
        }
        ResponseList<Place> places = twitter.getSimilarPlaces(location, name, containedWithin, null);
        if (places.size() == 0) {
            System.out.println("No location associated with the specified condition");
        } else {
            for (Place place : places) {
                System.out.println("id: " + place.getId() + " name: " + place.getFullName() + " name: "
                        + place.getFullName());
                Place[] containedWithinArray = place.getContainedWithIn();
                if (containedWithinArray != null && containedWithinArray.length != 0) {
                    System.out.println("  contained within:");
                    for (Place containedWithinPlace : containedWithinArray) {
                        System.out.println("  id: " + containedWithinPlace.getId() + " name: "
                                + containedWithinPlace.getFullName());
                    }
                }
            }
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to find similar places: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:geo.ReverseGeoCode.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.ReverseGeoCode [latitude] [longitude]
 *
 * @param args message//from   w w w .  j a va 2s  . c  o m
 */
public static void main(String[] args) {
    if (args.length < 2) {
        System.out.println("Usage: java twitter4j.examples.geo.ReverseGeoCode [latitude] [longitude]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        GeoQuery query = new GeoQuery(
                new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1])));
        ResponseList<Place> places = twitter.reverseGeoCode(query);
        if (places.size() == 0) {
            System.out.println("No location associated with the specified lat/lang");
        } else {
            for (Place place : places) {
                System.out.println("id: " + place.getId() + " name: " + place.getFullName());
                Place[] containedWithinArray = place.getContainedWithIn();
                if (containedWithinArray != null && containedWithinArray.length != 0) {
                    System.out.println("  contained within:");
                    for (Place containedWithinPlace : containedWithinArray) {
                        System.out.println("  id: " + containedWithinPlace.getId() + " name: "
                                + containedWithinPlace.getFullName());
                    }
                }
            }
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to retrieve places: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:geo.SearchPlaces.java

License:Apache License

/**
 * Usage: java twitter4j.examples.geo.SearchPlaces [ip address] or [latitude] [longitude]
 *
 * @param args message/*from  w  ww  . j  a v a  2  s .  co m*/
 */
public static void main(String[] args) {
    if (args.length < 1) {
        System.out.println(
                "Usage: java twitter4j.examples.geo.SearchPlaces [ip address] or [latitude] [longitude]");
        System.exit(-1);
    }
    try {
        Twitter twitter = new TwitterFactory().getInstance();
        GeoQuery query;
        if (args.length == 2) {
            query = new GeoQuery(new GeoLocation(Double.parseDouble(args[0]), Double.parseDouble(args[1])));
        } else {
            query = new GeoQuery(args[0]);
        }
        ResponseList<Place> places = twitter.searchPlaces(query);
        if (places.size() == 0) {
            System.out.println("No location associated with the specified IP address or lat/lang");
        } else {
            for (Place place : places) {
                System.out.println("id: " + place.getId() + " name: " + place.getFullName());
                Place[] containedWithinArray = place.getContainedWithIn();
                if (containedWithinArray != null && containedWithinArray.length != 0) {
                    System.out.println("  contained within:");
                    for (Place containedWithinPlace : containedWithinArray) {
                        System.out.println("  id: " + containedWithinPlace.getId() + " name: "
                                + containedWithinPlace.getFullName());
                    }
                }
            }
        }
        System.exit(0);
    } catch (TwitterException te) {
        te.printStackTrace();
        System.out.println("Failed to retrieve places: " + te.getMessage());
        System.exit(-1);
    }
}

From source file:io.rakam.datasource.twitter.TweetProcessor.java

License:Apache License

@Override
public void onStatus(Status status) {
    Map<String, Object> map = new HashMap<>();

    GeoLocation geoLocation = status.getGeoLocation();
    if (geoLocation != null) {
        map.put("latitude", geoLocation.getLatitude());
        map.put("longitude", geoLocation.getLongitude());
    }//from   www.  j  a  v  a2s .c om

    map.put("_time", status.getCreatedAt().getTime());
    Place place = status.getPlace();
    if (place != null) {
        map.put("country_code", place.getCountryCode());
        map.put("place", place.getName());
        map.put("place_type", place.getPlaceType());
        map.put("place_id", place.getId());
    }

    User user = status.getUser();
    map.put("_user", user.getId());
    map.put("user_lang", user.getLang());
    map.put("user_created", user.getCreatedAt());
    map.put("user_followers", user.getFollowersCount());
    map.put("user_status_count", user.getStatusesCount());
    map.put("user_verified", user.isVerified());

    map.put("id", status.getId());
    map.put("is_reply", status.getInReplyToUserId() > -1);
    map.put("is_retweet", status.isRetweet());
    map.put("has_media", status.getMediaEntities().length > 0);
    map.put("urls",
            Arrays.stream(status.getURLEntities()).map(URLEntity::getText).collect(Collectors.toList()));
    map.put("hashtags", Arrays.stream(status.getHashtagEntities()).map(HashtagEntity::getText)
            .collect(Collectors.toList()));
    map.put("user_mentions", Arrays.stream(status.getUserMentionEntities()).map(UserMentionEntity::getText)
            .collect(Collectors.toList()));
    map.put("language", "und".equals(status.getLang()) ? null : status.getLang());
    map.put("is_positive", classifier.isPositive(status.getText()));

    Event event = new Event().properties(map).collection(collection);
    buffer.add(event);

    commitIfNecessary();
}

From source file:org.bireme.interop.toJson.Twitter2Json.java

License:Open Source License

private JSONObject getDocument(final Status status) {
    assert status != null;

    final JSONObject obj = new JSONObject();
    final GeoLocation geo = status.getGeoLocation();
    final Place place = status.getPlace();
    final User user = status.getUser();

    obj.put("createdAt", status.getCreatedAt()).put("id", status.getId()).put("lang", status.getLang());
    if (geo != null) {
        obj.put("location_latitude", geo.getLatitude()).put("location_longitude", geo.getLongitude());
    }/*  www .  java  2s  .  c  o  m*/
    if (place != null) {
        obj.put("place_country", place.getCountry()).put("place_fullName", place.getFullName())
                .put("place_id", place.getId()).put("place_name", place.getName())
                .put("place_type", place.getPlaceType()).put("place_streetAddress", place.getStreetAddress())
                .put("place_url", place.getURL());
    }
    obj.put("source", status.getSource()).put("text", status.getText());
    if (user != null) {
        obj.put("user_description", user.getDescription()).put("user_id", user.getId())
                .put("user_lang", user.getLang()).put("user_location", user.getLocation())
                .put("user_name", user.getName()).put("user_url", user.getURL());
    }
    obj.put("isTruncated", status.isTruncated()).put("isRetweet", status.isRetweet());

    return obj;
}