Example usage for twitter4j Status getInReplyToStatusId

List of usage examples for twitter4j Status getInReplyToStatusId

Introduction

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

Prototype

long getInReplyToStatusId();

Source Link

Document

Returns the in_reply_tostatus_id

Usage

From source file:de.vanita5.twittnuker.loader.support.StatusRepliesLoader.java

License:Open Source License

@Override
public List<Status> getStatuses(final Twitter twitter, final Paging paging) throws TwitterException {
    final Context context = getContext();
    if (shouldForceUsingPrivateAPIs(context) || isOfficialTwitterInstance(context, twitter)) {
        final List<Status> statuses = twitter.showConversation(mInReplyToStatusId, paging);
        final List<Status> result = new ArrayList<Status>();
        for (final Status status : statuses) {
            if (status.getId() > mInReplyToStatusId) {
                result.add(status);//from  w w  w.  ja v  a2 s . com
            }
        }
        return result;
    } else {
        final List<Status> statuses = super.getStatuses(twitter, paging);
        final List<Status> result = new ArrayList<Status>();
        for (final Status status : statuses) {
            if (status.getInReplyToStatusId() == mInReplyToStatusId) {
                result.add(status);
            }
        }
        return result;
    }
}

From source file:de.vanita5.twittnuker.model.ParcelableStatus.java

License:Open Source License

public ParcelableStatus(final Status orig, final long account_id, final boolean is_gap) {
    this.is_gap = is_gap;
    this.account_id = account_id;
    id = orig.getId();/*from   w  w  w .  ja  v  a  2 s . c om*/
    timestamp = getTime(orig.getCreatedAt());
    is_retweet = orig.isRetweet();
    final Status retweeted = orig.getRetweetedStatus();
    final User retweet_user = retweeted != null ? orig.getUser() : null;
    retweet_id = retweeted != null ? retweeted.getId() : -1;
    //NOTE getTime(orig.getCreatedAt())
    retweet_timestamp = retweeted != null ? getTime(retweeted.getCreatedAt()) : -1;
    retweeted_by_id = retweet_user != null ? retweet_user.getId() : -1;
    retweeted_by_name = retweet_user != null ? retweet_user.getName() : null;
    retweeted_by_screen_name = retweet_user != null ? retweet_user.getScreenName() : null;
    retweeted_by_profile_image = retweet_user != null
            ? ParseUtils.parseString(retweet_user.getProfileImageUrlHttps())
            : null;
    final Status status = retweeted != null ? retweeted : orig;
    final User user = status.getUser();
    user_id = user.getId();
    user_name = user.getName();
    user_screen_name = user.getScreenName();
    user_profile_image_url = ParseUtils.parseString(user.getProfileImageUrlHttps());
    user_is_protected = user.isProtected();
    user_is_verified = user.isVerified();
    user_is_following = user.isFollowing();
    text_html = formatStatusText(status);
    media = ParcelableMedia.fromEntities(status);
    text_plain = status.getText();
    retweet_count = status.getRetweetCount();
    favorite_count = status.getFavoriteCount();
    reply_count = status.getReplyCount();
    descendent_reply_count = status.getDescendentReplyCount();
    in_reply_to_name = getInReplyToName(status);
    in_reply_to_screen_name = status.getInReplyToScreenName();
    in_reply_to_status_id = status.getInReplyToStatusId();
    in_reply_to_user_id = status.getInReplyToUserId();
    source = status.getSource();
    location = new ParcelableLocation(status.getGeoLocation());
    is_favorite = status.isFavorited();
    text_unescaped = toPlainText(text_html);
    my_retweet_id = retweeted_by_id == account_id ? id : -1;
    is_possibly_sensitive = status.isPossiblySensitive();
    mentions = ParcelableUserMention.fromUserMentionEntities(status.getUserMentionEntities());
    first_media = media != null && media.length > 0 ? media[0].url : null;
}

From source file:de.vanita5.twittnuker.util.ContentValuesCreator.java

License:Open Source License

public static ContentValues makeStatusContentValues(final Status orig, final long accountId,
        final boolean largeProfileImage) {
    if (orig == null || orig.getId() <= 0)
        return null;
    final ContentValues values = new ContentValues();
    values.put(Statuses.ACCOUNT_ID, accountId);
    values.put(Statuses.STATUS_ID, orig.getId());
    values.put(Statuses.STATUS_TIMESTAMP, orig.getCreatedAt().getTime());
    values.put(Statuses.MY_RETWEET_ID, orig.getCurrentUserRetweet());
    final boolean isRetweet = orig.isRetweet();
    final Status status;
    final Status retweetedStatus = isRetweet ? orig.getRetweetedStatus() : null;
    if (retweetedStatus != null) {
        final User retweetUser = orig.getUser();
        values.put(Statuses.RETWEET_ID, retweetedStatus.getId());
        values.put(Statuses.RETWEET_TIMESTAMP, retweetedStatus.getCreatedAt().getTime());
        values.put(Statuses.RETWEETED_BY_USER_ID, retweetUser.getId());
        values.put(Statuses.RETWEETED_BY_USER_NAME, retweetUser.getName());
        values.put(Statuses.RETWEETED_BY_USER_SCREEN_NAME, retweetUser.getScreenName());
        values.put(Statuses.RETWEETED_BY_USER_PROFILE_IMAGE,
                ParseUtils.parseString(retweetUser.getProfileImageUrlHttps()));
        status = retweetedStatus;// w  w w .  j  ava2s .c om
    } else {
        status = orig;
    }
    final User user = status.getUser();
    if (user != null) {
        final long userId = user.getId();
        final String profileImageUrl = ParseUtils.parseString(user.getProfileImageUrlHttps());
        final String name = user.getName(), screenName = user.getScreenName();
        values.put(Statuses.USER_ID, userId);
        values.put(Statuses.USER_NAME, name);
        values.put(Statuses.USER_SCREEN_NAME, screenName);
        values.put(Statuses.IS_PROTECTED, user.isProtected());
        values.put(Statuses.IS_VERIFIED, user.isVerified());
        values.put(Statuses.USER_PROFILE_IMAGE_URL,
                largeProfileImage ? getBiggerTwitterProfileImage(profileImageUrl) : profileImageUrl);
        values.put(CachedUsers.IS_FOLLOWING, user.isFollowing());
    }
    final String text_html = Utils.formatStatusText(status);
    values.put(Statuses.TEXT_HTML, text_html);
    values.put(Statuses.TEXT_PLAIN, status.getText());
    values.put(Statuses.TEXT_UNESCAPED, toPlainText(text_html));
    values.put(Statuses.RETWEET_COUNT, status.getRetweetCount());
    values.put(Statuses.REPLY_COUNT, status.getReplyCount());
    values.put(Statuses.DESCENDENT_REPLY_COUNT, status.getDescendentReplyCount());
    values.put(Statuses.IN_REPLY_TO_STATUS_ID, status.getInReplyToStatusId());
    values.put(Statuses.IN_REPLY_TO_USER_ID, status.getInReplyToUserId());
    values.put(Statuses.IN_REPLY_TO_USER_NAME, Utils.getInReplyToName(status));
    values.put(Statuses.IN_REPLY_TO_USER_SCREEN_NAME, status.getInReplyToScreenName());
    values.put(Statuses.SOURCE, status.getSource());
    values.put(Statuses.IS_POSSIBLY_SENSITIVE, status.isPossiblySensitive());
    final GeoLocation location = status.getGeoLocation();
    if (location != null) {
        values.put(Statuses.LOCATION, location.getLatitude() + "," + location.getLongitude());
    }
    values.put(Statuses.IS_RETWEET, isRetweet);
    values.put(Statuses.IS_FAVORITE, status.isFavorited());
    final ParcelableMedia[] media = ParcelableMedia.fromEntities(status);
    if (media != null) {
        values.put(Statuses.MEDIA, JSONSerializer.toJSONArrayString(media));
        values.put(Statuses.FIRST_MEDIA, media[0].url);
    }
    final ParcelableUserMention[] mentions = ParcelableUserMention.fromStatus(status);
    if (mentions != null) {
        values.put(Statuses.MENTIONS, JSONSerializer.toJSONArrayString(mentions));
    }
    return values;
}

From source file:edu.cmu.cs.lti.discoursedb.io.twitter.converter.TwitterConverterService.java

License:Open Source License

/**
 * Maps a Tweet represented as a Twitter4J Status object to DiscourseDB
 * //www .  j a  va2  s.  c  o  m
 * @param discourseName the name of the discourse
 * @param datasetName the dataset identifier
 * @param tweet the Tweet to store in DiscourseDB
 */
public void mapTweet(String discourseName, String datasetName, Status tweet, PemsStationMetaData pemsMetaData) {
    if (tweet == null) {
        return;
    }

    Assert.hasText(discourseName, "The discourse name has to be specified and cannot be empty.");
    Assert.hasText(datasetName, "The dataset name has to be specified and cannot be empty.");

    if (dataSourceService.dataSourceExists(String.valueOf(tweet.getId()), TweetSourceMapping.ID_TO_CONTRIBUTION,
            datasetName)) {
        log.trace("Tweet with id " + tweet.getId() + " already exists in database. Skipping");
        return;
    }
    log.trace("Mapping Tweet " + tweet.getId());

    Discourse discourse = discourseService.createOrGetDiscourse(discourseName);

    twitter4j.User tUser = tweet.getUser();
    User user = null;
    if (!userService.findUserByDiscourseAndUsername(discourse, tUser.getScreenName()).isPresent()) {
        user = userService.createOrGetUser(discourse, tUser.getScreenName());
        user.setRealname(tUser.getName());
        user.setEmail(tUser.getEmail());
        user.setLocation(tUser.getLocation());
        user.setLanguage(tUser.getLang());
        user.setStartTime(tweet.getUser().getCreatedAt());

        AnnotationInstance userInfo = annoService.createTypedAnnotation("twitter_user_info");
        annoService.addFeature(userInfo,
                annoService.createTypedFeature(String.valueOf(tUser.getFavouritesCount()), "favorites_count"));
        annoService.addFeature(userInfo,
                annoService.createTypedFeature(String.valueOf(tUser.getFollowersCount()), "followers_count"));
        annoService.addFeature(userInfo,
                annoService.createTypedFeature(String.valueOf(tUser.getFriendsCount()), "friends_count"));
        annoService.addFeature(userInfo,
                annoService.createTypedFeature(String.valueOf(tUser.getStatusesCount()), "statuses_count"));
        annoService.addFeature(userInfo,
                annoService.createTypedFeature(String.valueOf(tUser.getListedCount()), "listed_count"));
        if (tUser.getDescription() != null) {
            annoService.addFeature(userInfo,
                    annoService.createTypedFeature(String.valueOf(tUser.getDescription()), "description"));
        }
        annoService.addAnnotation(user, userInfo);
    }

    Contribution curContrib = contributionService.createTypedContribution(ContributionTypes.TWEET);
    DataSourceInstance contribSource = dataSourceService.createIfNotExists(new DataSourceInstance(
            String.valueOf(tweet.getId()), TweetSourceMapping.ID_TO_CONTRIBUTION, datasetName));
    curContrib.setStartTime(tweet.getCreatedAt());
    dataSourceService.addSource(curContrib, contribSource);

    AnnotationInstance tweetInfo = annoService.createTypedAnnotation("twitter_tweet_info");
    if (tweet.getSource() != null) {
        annoService.addFeature(tweetInfo, annoService.createTypedFeature(tweet.getSource(), "tweet_source"));
    }

    annoService.addFeature(tweetInfo,
            annoService.createTypedFeature(String.valueOf(tweet.getFavoriteCount()), "favorites_count"));

    if (tweet.getHashtagEntities() != null) {
        for (HashtagEntity hashtag : tweet.getHashtagEntities()) {
            annoService.addFeature(tweetInfo, annoService.createTypedFeature(hashtag.getText(), "hashtag"));
        }
    }

    if (tweet.getMediaEntities() != null) {
        for (MediaEntity media : tweet.getMediaEntities()) {
            //NOTE: additional info is available for MediaEntities
            annoService.addFeature(tweetInfo, annoService.createTypedFeature(media.getMediaURL(), "media_url"));
        }
    }

    //TODO this should be represented as a relation if the related tweet is part of the dataset
    if (tweet.getInReplyToStatusId() > 0) {
        annoService.addFeature(tweetInfo, annoService
                .createTypedFeature(String.valueOf(tweet.getInReplyToStatusId()), "in_reply_to_status_id"));
    }

    //TODO this should be represented as a relation if the related tweet is part of the dataset
    if (tweet.getInReplyToScreenName() != null) {
        annoService.addFeature(tweetInfo,
                annoService.createTypedFeature(tweet.getInReplyToScreenName(), "in_reply_to_screen_name"));
    }
    annoService.addAnnotation(curContrib, tweetInfo);

    GeoLocation geo = tweet.getGeoLocation();
    if (geo != null) {
        AnnotationInstance coord = annoService.createTypedAnnotation("twitter_tweet_geo_location");
        annoService.addFeature(coord,
                annoService.createTypedFeature(String.valueOf(geo.getLongitude()), "long"));
        annoService.addFeature(coord, annoService.createTypedFeature(String.valueOf(geo.getLatitude()), "lat"));
        annoService.addAnnotation(curContrib, coord);
    }

    Place place = tweet.getPlace();
    if (place != null) {
        AnnotationInstance placeAnno = annoService.createTypedAnnotation("twitter_tweet_place");
        annoService.addFeature(placeAnno,
                annoService.createTypedFeature(String.valueOf(place.getPlaceType()), "place_type"));
        if (place.getGeometryType() != null) {
            annoService.addFeature(placeAnno,
                    annoService.createTypedFeature(String.valueOf(place.getGeometryType()), "geo_type"));
        }
        annoService.addFeature(placeAnno, annoService
                .createTypedFeature(String.valueOf(place.getBoundingBoxType()), "bounding_box_type"));
        annoService.addFeature(placeAnno,
                annoService.createTypedFeature(String.valueOf(place.getFullName()), "place_name"));
        if (place.getStreetAddress() != null) {
            annoService.addFeature(placeAnno,
                    annoService.createTypedFeature(String.valueOf(place.getStreetAddress()), "street_address"));
        }
        annoService.addFeature(placeAnno,
                annoService.createTypedFeature(String.valueOf(place.getCountry()), "country"));
        if (place.getBoundingBoxCoordinates() != null) {
            annoService.addFeature(placeAnno, annoService.createTypedFeature(
                    convertGeoLocationArray(place.getBoundingBoxCoordinates()), "bounding_box_lat_lon_array"));
        }
        if (place.getGeometryCoordinates() != null) {
            annoService.addFeature(placeAnno, annoService.createTypedFeature(
                    convertGeoLocationArray(place.getGeometryCoordinates()), "geometry_lat_lon_array"));
        }
        annoService.addAnnotation(curContrib, placeAnno);
    }

    Content curContent = contentService.createContent();
    curContent.setText(tweet.getText());
    curContent.setAuthor(user);
    curContent.setStartTime(tweet.getCreatedAt());
    curContrib.setCurrentRevision(curContent);
    curContrib.setFirstRevision(curContent);

    DataSourceInstance contentSource = dataSourceService.createIfNotExists(new DataSourceInstance(
            String.valueOf(tweet.getId()), TweetSourceMapping.ID_TO_CONTENT, datasetName));
    dataSourceService.addSource(curContent, contentSource);

    if (pemsMetaData != null) {
        log.warn("PEMS station meta data mapping not implemented yet");
        //TODO map pems meta data if available         
    }
}

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();/* w  w w  .ja  v  a2  s .c  om*/

    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:net.lacolaco.smileessence.view.dialog.TalkChainDialogFragment.java

License:Open Source License

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    MainActivity activity = (MainActivity) getActivity();
    final Account account = activity.getCurrentAccount();

    View view = getActivity().getLayoutInflater().inflate(R.layout.dialog_talk_list, null);
    ListView listView = (ListView) view.findViewById(R.id.listview_dialog_talk_list);
    final StatusListAdapter adapter = new StatusListAdapter(getActivity());
    listView.setAdapter(adapter);/* w w  w.  ja v a2  s . com*/
    TwitterUtils.tryGetStatus(account, getStatusID(), new TwitterUtils.StatusCallback() {
        @Override
        public void success(Status status) {
            adapter.addToTop(new StatusViewModel(status, account));
            adapter.updateForce();
            Twitter twitter = TwitterApi.getTwitter(account);
            new GetTalkTask(twitter, account, adapter, status.getInReplyToStatusId()).execute();
        }

        @Override
        public void error() {
            dismiss();
        }
    });

    return new AlertDialog.Builder(activity).setTitle(R.string.dialog_title_talk_chain).setView(view)
            .setCancelable(true).create();
}

From source file:net.nokok.twitduke.core.twitter.StatusParser.java

License:Open Source License

/**
 * ???????????/*w w w . j a  v a  2  s . c o  m*/
 *
 * @param status ??
 *
 * @return ????
 */
public LinkedList<Status> createReplyChain(Status status) {
    LinkedList<Status> linkedList = new LinkedList<>();
    Status currentStatus = status;
    long currentStatusId;
    while ((currentStatusId = currentStatus.getInReplyToStatusId()) > 0) {
        linkedList.add(currentStatus);
        try {
            currentStatus = twitter.showStatus(currentStatusId);
        } catch (TwitterException e) {
            return linkedList;
        }
    }
    return linkedList;
}

From source file:nl.isaac.dotcms.twitter.pojo.CustomStatus.java

License:Creative Commons License

public CustomStatus(Status status) {
    this.createdAt = status.getCreatedAt();
    this.id = status.getId();
    this.id_str = String.valueOf(status.getId());
    this.text = status.getText();
    this.source = status.getSource();
    this.isTruncated = status.isTruncated();
    this.inReplyToStatusId = status.getInReplyToStatusId();
    this.inReplyToUserId = status.getInReplyToUserId();
    this.isFavorited = status.isFavorited();
    this.inReplyToScreenName = status.getInReplyToScreenName();
    this.geoLocation = status.getGeoLocation();
    this.place = status.getPlace();
    this.retweetCount = status.getRetweetCount();
    this.isPossiblySensitive = status.isPossiblySensitive();

    this.contributorsIDs = status.getContributors();

    this.retweetedStatus = status.getRetweetedStatus();
    this.userMentionEntities = status.getUserMentionEntities();
    this.urlEntities = status.getURLEntities();
    this.hashtagEntities = status.getHashtagEntities();
    this.mediaEntities = status.getMediaEntities();
    this.currentUserRetweetId = status.getCurrentUserRetweetId();

    this.isRetweet = status.isRetweet();
    this.isRetweetedByMe = status.isRetweetedByMe();

    this.rateLimitStatus = status.getRateLimitStatus();
    this.accessLevel = status.getAccessLevel();
    this.user = status.getUser();
}

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();//from w  ww. ja  va2  s  . c o m
    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());
    }

    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.botlibre.sense.twitter.Twitter.java

License:Open Source License

public void learnTweet(Status tweet, boolean processTweets, boolean processReplies, Network memory)
        throws Exception {
    String text = tweet.getText();
    // Exclude retweets
    if (tweet.isRetweet()) {
        log("Tweet is retweet", Level.FINER, tweet.getText());
        return;//from   w  ww . jav  a2 s  .c o m
    }
    if (Utils.checkProfanity(text)) {
        log("Ignoring profanity", Level.INFO, text);
        return;
    }
    // Exclude protected
    if (tweet.getUser().isProtected() && !tweet.getUser().getScreenName().equals(getUserName())) {
        log("Tweet is protected", Level.FINER, tweet.getText());
        return;
    }
    log("Learning status", Level.INFO, text);
    // Exclude replies/mentions
    if (tweet.getText().indexOf('@') != -1) {
        log("Tweet is reply", Level.FINER, tweet.getText());
        if (!processReplies) {
            return;
        }
        long id = tweet.getInReplyToStatusId();
        if (id > 0) {
            try {
                Status reply = getConnection().showStatus(id);
                String replyText = reply.getText();
                if (replyText != null && !replyText.isEmpty()) {
                    // Filter out @users
                    for (String word : new TextStream(text).allWords()) {
                        if (word.startsWith("@")) {
                            text = text.replace(word, "");
                        }
                    }
                    for (String word : new TextStream(replyText).allWords()) {
                        if (word.startsWith("@")) {
                            replyText = replyText.replace(word, "");
                        }
                    }
                    Vertex question = memory.createSentence(replyText.trim());
                    Vertex sentence = memory.createSentence(text.trim());
                    Language.addResponse(question, sentence, memory);
                }
            } catch (Exception ignore) {
                log(ignore.toString(), Level.WARNING);
            }

        }
        return;
    }
    if (!processTweets) {
        return;
    }
    Vertex sentence = memory.createSentence(text);
    String keywords = "";
    for (String word : new TextStream(text).allWords()) {
        if (word.startsWith("#")) {
            keywords = keywords + " " + word + " " + word.substring(1, word.length());
        }
    }
    Language.addResponse(sentence, sentence, null, keywords, null, memory);
}