Example usage for twitter4j User getDescription

List of usage examples for twitter4j User getDescription

Introduction

In this page you can find the example usage for twitter4j User getDescription.

Prototype

String getDescription();

Source Link

Document

Returns the description of the user

Usage

From source file:edu.cmu.geolocator.coder.utils.JSON2Tweet.java

License:Apache License

public JSONTweet readLine() {
    String line;// ww w  .  j  av  a2  s.  c om
    try {
        line = br.readLine();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
        return null;
    }
    if (line == null)
        return null;

    Status tweet = null;
    try {
        // parse json to object type
        tweet = DataObjectFactory.createStatus(line);
    } catch (TwitterException e) {
        System.err.println("error parsing tweet object");
        return null;
    }

    jsontweet.JSON = line;
    jsontweet.id = tweet.getId();
    jsontweet.source = tweet.getSource();
    jsontweet.text = tweet.getText();
    jsontweet.createdat = tweet.getCreatedAt();
    jsontweet.tweetgeolocation = tweet.getGeoLocation();

    User user;
    if ((user = tweet.getUser()) != null) {

        jsontweet.userdescription = user.getDescription();
        jsontweet.userid = user.getId();
        jsontweet.userlanguage = user.getLang();
        jsontweet.userlocation = user.getLocation();
        jsontweet.username = user.getName();
        jsontweet.usertimezone = user.getTimeZone();
        jsontweet.usergeoenabled = user.isGeoEnabled();

        if (user.getURL() != null) {
            String url = user.getURL().toString();

            jsontweet.userurl = url;

            String addr = url.substring(7).split("/")[0];
            String[] countrysuffix = addr.split("[.]");
            String suffix = countrysuffix[countrysuffix.length - 1];

            jsontweet.userurlsuffix = suffix;

            try {
                InetAddress address = null;//InetAddress.getByName(user.getURL().getHost());

                String generate_URL
                // =
                // "http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress="
                        = "http://www.geoplugin.net/php.gp?ip=" + address.getHostAddress();
                URL data = new URL(generate_URL);
                URLConnection yc = data.openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
                String inputLine;
                String temp = "";
                while ((inputLine = in.readLine()) != null) {
                    temp += inputLine + "\n";
                }
                temp = temp.split("s:2:\"")[1].split("\"")[0];

                jsontweet.userurllocation = temp;

            } catch (Exception uhe) {
                //uhe.printStackTrace();
                jsontweet.userurllocation = null;
            }
        }
    }

    return jsontweet;

}

From source file:edu.cmu.geolocator.coder.utils.JSON2Tweet.java

License:Apache License

public static JSONTweet getJSONTweet(String JSONString) {
    JSONTweet jsontweet = new JSONTweet();
    if (JSONString == null)
        return null;

    Status tweet = null;/*  ww w.  j a va  2  s .c  om*/
    try {
        // parse json to object type
        tweet = DataObjectFactory.createStatus(JSONString);
    } catch (TwitterException e) {
        System.err.println("error parsing tweet object");
        return null;
    }

    jsontweet.JSON = JSONString;
    jsontweet.id = tweet.getId();
    jsontweet.source = tweet.getSource();
    jsontweet.text = tweet.getText();
    jsontweet.createdat = tweet.getCreatedAt();
    jsontweet.tweetgeolocation = tweet.getGeoLocation();

    User user;
    if ((user = tweet.getUser()) != null) {

        jsontweet.userdescription = user.getDescription();
        jsontweet.userid = user.getId();
        jsontweet.userlanguage = user.getLang();
        jsontweet.userlocation = user.getLocation();
        jsontweet.username = user.getName();
        jsontweet.usertimezone = user.getTimeZone();
        jsontweet.usergeoenabled = user.isGeoEnabled();

        if (user.getURL() != null) {
            String url = user.getURL().toString();

            jsontweet.userurl = url;

            String addr = url.substring(7).split("/")[0];
            String[] countrysuffix = addr.split("[.]");
            String suffix = countrysuffix[countrysuffix.length - 1];

            jsontweet.userurlsuffix = suffix;

            try {
                InetAddress address = null;//InetAddress.getByName(user.getURL().getHost());

                String generate_URL
                // =
                // "http://www.geobytes.com/IpLocator.htm?GetLocation&template=php3.txt&IpAddress="
                        = "http://www.geoplugin.net/php.gp?ip=" + address.getHostAddress();
                URL data = new URL(generate_URL);
                URLConnection yc = data.openConnection();
                BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
                String inputLine;
                String temp = "";
                while ((inputLine = in.readLine()) != null) {
                    temp += inputLine + "\n";
                }
                temp = temp.split("s:2:\"")[1].split("\"")[0];

                jsontweet.userurllocation = temp;

            } catch (Exception uhe) {
                //uhe.printStackTrace();
                jsontweet.userurllocation = null;
            }
        }
    }

    return jsontweet;

}

From source file:info.maslowis.twitterripper.util.Util.java

License:Open Source License

/**
 * Returns a representation the user as string
 *
 * @return a representation the user as string in format <em>User{id=, name='', screenName='', location='', description=''}</em>
 *//*w  ww .  ja v  a  2s  .  c o m*/
public static String toString(final User user) {
    return "User{id=" + user.getId() + ", name='" + user.getName() + "', screenName='" + user.getScreenName()
            + "', location='" + user.getLocation() + "', description='" + user.getDescription() + "'}";
}

From source file:kr.debop4j.search.twitter.Twitters.java

License:Apache License

protected static String getUserAsString(User user) {
    StringBuilder sb = new StringBuilder();
    return sb.append("id=").append(user.getId()).append(",").append("name=").append(user.getName()).append(",")
            .append("screenName=").append(user.getScreenName()).append(",").append("description=")
            .append(user.getDescription()).toString();
}

From source file:net.lacolaco.smileessence.view.dialog.UserDetailDialogFragment.java

License:Open Source License

private void initUserData(User user, final Account account) {
    textViewName.setText(user.getName());
    textViewScreenName.setText(user.getScreenName());
    if (TextUtils.isEmpty(user.getLocation())) {
        textViewLocate.setVisibility(View.GONE);
    } else {//w  w  w  . j a va2  s. c o m
        textViewLocate.setText(user.getLocation());
    }
    if (TextUtils.isEmpty(user.getURL())) {
        textViewURL.setVisibility(View.GONE);
    } else {
        textViewURL.setText(user.getURL());
    }
    textViewTweetCount.setText(String.valueOf(user.getStatusesCount()));
    textViewFriendCount.setText(String.valueOf(user.getFriendsCount()));
    textViewFollowerCount.setText(String.valueOf(user.getFollowersCount()));
    textViewFavoriteCount.setText(String.valueOf(user.getFavouritesCount()));
    textViewProtected.setVisibility(user.isProtected() ? View.VISIBLE : View.GONE);
    String htmlDescription = getHtmlDescription(user.getDescription());
    textViewDescription.setText(Html.fromHtml(htmlDescription));
    textViewDescription.setMovementMethod(LinkMovementMethod.getInstance());
    ImageCache.getInstance().setImageToView(user.getBiggerProfileImageURL(), imageViewIcon);
    ImageCache.getInstance().setImageToView(user.getProfileBannerURL(), imageViewHeader);
    MainActivity activity = (MainActivity) getActivity();
    final StatusListAdapter adapter = new StatusListAdapter(activity);
    listViewTimeline.setAdapter(adapter);
    listViewTimeline.setOnRefreshListener(this);
    activity.setListAdapter(ADAPTER_INDEX, adapter);
    executeUserTimelineTask(user, account, adapter);
    updateRelationship(activity, user.getId());
}

From source file:net.lacolaco.smileessence.viewmodel.UserViewModel.java

License:Open Source License

public UserViewModel(User user) {
    id = user.getId();/*from ww w .j a v a  2 s. co m*/
    screenName = user.getScreenName();
    name = user.getName();
    description = user.getDescription();
    location = user.getLocation();
    url = user.getURL();
    iconURL = user.getBiggerProfileImageURL();
    bannerURL = user.getProfileBannerURL();
    statusesCount = user.getStatusesCount();
    friendsCount = user.getFriendsCount();
    followersCount = user.getFollowersCount();
    favoritesCount = user.getFavouritesCount();
    isProtected = user.isProtected();
    isVerified = user.isVerified();
}

From source file:org.apache.flume.sink.solr.morphline.TwitterSource.java

License:Apache License

private Record extractRecord(String idPrefix, Schema avroSchema, Status status) {
    User user = status.getUser();
    Record doc = new Record(avroSchema);

    doc.put("id", idPrefix + status.getId());
    doc.put("created_at", formatterTo.format(status.getCreatedAt()));
    doc.put("retweet_count", status.getRetweetCount());
    doc.put("retweeted", status.isRetweet());
    doc.put("in_reply_to_user_id", status.getInReplyToUserId());
    doc.put("in_reply_to_status_id", status.getInReplyToStatusId());

    addString(doc, "source", status.getSource());
    addString(doc, "text", status.getText());

    MediaEntity[] mediaEntities = status.getMediaEntities();
    if (mediaEntities.length > 0) {
        addString(doc, "media_url_https", mediaEntities[0].getMediaURLHttps());
        addString(doc, "expanded_url", mediaEntities[0].getExpandedURL());
    }/*w ww.j a  v a 2  s .com*/

    doc.put("user_friends_count", user.getFriendsCount());
    doc.put("user_statuses_count", user.getStatusesCount());
    doc.put("user_followers_count", user.getFollowersCount());
    addString(doc, "user_location", user.getLocation());
    addString(doc, "user_description", user.getDescription());
    addString(doc, "user_screen_name", user.getScreenName());
    addString(doc, "user_name", user.getName());
    return doc;
}

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());
    }/*from  w w w  . j  a va  2s  . com*/
    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;
}

From source file:org.botlibre.sense.twitter.Twitter.java

License:Open Source License

public boolean checkFriendship(long friendId, boolean welcomeOnly) throws TwitterException {
    long[] lookup = new long[1];
    lookup[0] = friendId;/* www.j ava2s . com*/
    ResponseList<User> users = getConnection().lookupUsers(lookup);
    User friend = users.get(0);
    if (friend.getScreenName().equals(getUserName())) {
        return false;
    }
    if (!getAutoFollowKeywords().isEmpty()) {
        StringWriter writer = new StringWriter();
        writer.write(friend.getScreenName().toLowerCase());
        writer.write(" ");
        writer.write(friend.getDescription().toLowerCase());
        writer.write(" ");
        writer.write(friend.getLocation().toLowerCase());
        writer.write(" ");
        writer.write(friend.getLang().toLowerCase());
        writer.write(" ");
        writer.write(friend.getName().toLowerCase());
        boolean match = false;
        for (String text : getAutoFollowKeywords()) {
            List<String> keywords = new TextStream(text.toLowerCase()).allWords();
            if (new TextStream(writer.toString()).allWords().containsAll(keywords)) {
                match = true;
                break;
            }
        }
        if (!match) {
            log("Autofollow skipping friend, does not match keywords", Level.FINE, friend.getScreenName());
            return false;
        }
    }
    Network memory = getBot().memory().newMemory();
    Vertex speaker = memory.createSpeaker(friend.getScreenName());
    speaker.setPinned(true);
    // Only try to follow a user once.
    if (!speaker.hasRelationship(Primitive.FOLLOWED)) {
        speaker.addRelationship(Primitive.FOLLOWED, memory.createTimestamp());
        memory.save();
        if (!welcomeOnly && getAutoFollow()) {
            log("Adding autofollow friend.", Level.INFO, friend.getScreenName());
            getConnection().createFriendship(friendId);
            Utils.sleep(1000);
        }
        if (!getWelcomeMessage().isEmpty()) {
            log("Sending welcome message.", Level.INFO, friend.getScreenName());
            sendMessage(getWelcomeMessage(), friend.getScreenName());
            Utils.sleep(1000);
        }
        if (welcomeOnly) {
            return false;
        }
        return true;
    }
    log("Autofollow skipping friend, already followed once", Level.FINE, friend.getScreenName());
    return false;
}

From source file:org.encuestame.social.api.templates.TwitterAPITemplate.java

License:Apache License

@Override
public SocialUserProfile getProfile() throws Exception {
    final SocialUserProfile profile = new SocialUserProfile();
    User user = this.getUser();
    profile.setId(String.valueOf(user.getId()));
    profile.setCreatedAt(user.getCreatedAt());
    profile.setProfileUrl("http://www.twitter.com/" + user.getScreenName());
    profile.setName(user.getName());/*  w w  w .  j a v  a 2s .c  o  m*/
    profile.setScreenName(user.getScreenName());
    profile.setUsername(user.getScreenName());
    profile.setProfileImageUrl(user.getProfileImageURL().toString());
    profile.setDescription(user.getDescription());
    profile.setCreatedAt(user.getCreatedAt());
    profile.setLocation(user.getLocation());
    return profile;
}