Example usage for twitter4j Status getText

List of usage examples for twitter4j Status getText

Introduction

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

Prototype

String getText();

Source Link

Document

Returns the text of the status

Usage

From source file:com.tweetmyhome.TweetMyHome.java

@Override
public void onFavorite(User source, User target, Status favoritedStatus) {
    debug("onFavorite source:@" + source.getScreenName() + " target:@" + target.getScreenName() + " @"
            + favoritedStatus.getUser().getScreenName() + " - " + favoritedStatus.getText());
}

From source file:com.tweetmyhome.TweetMyHome.java

@Override
public void onUnfavorite(User source, User target, Status unfavoritedStatus) {
    debug("onUnFavorite source:@" + source.getScreenName() + " target:@" + target.getScreenName() + " @"
            + unfavoritedStatus.getUser().getScreenName() + " - " + unfavoritedStatus.getText());
}

From source file:com.twit.AppCrawler.java

public static void main(String[] args) throws TwitterException {

    TwitterFactory tf = new TwitterFactory();
    Twitter twitter = tf.getInstance();/*from w  ww. j a  v  a2 s  . c o  m*/

    CidadeController cidadeController = new CidadeController(new Cidade());
    List<Cidade> cidades = cidadeController.findEntities();

    String searchStr = "\"#viagem\" ";

    for (Cidade cidade : cidades) {

        //searchStr += "\"" + cidade.getNome() + "\" "; 

    }

    // Create a Query object.
    Query query = new Query(searchStr);

    // Send API request to execute a search with the given query.
    QueryResult result = twitter.search(query);

    // Display search results.
    for (Status status : result.getTweets()) {
        System.out.println("\n@" + status.getUser().getName() + ": " + status.getText());
    }

}

From source file:com.twitt4droid.data.dao.impl.sqlite.ListSQLiteDAO.java

License:Apache License

/** {@inheritDoc} */
@Override//from   www .  j  a  v  a 2s. com
public void save(final List<Status> statuses, final Long listId) {
    getSQLiteTemplate().batchExecute(getSqlString(R.string.twitt4droid_insert_list_status_sql),
            new SQLiteTemplate.BatchSQLiteStatementBinder() {

                @Override
                public int getBatchSize() {
                    return statuses.size();
                }

                @Override
                public void bindValues(SQLiteStatement statement, int i) {
                    Status status = statuses.get(i);
                    int index = 0;
                    statement.bindLong(++index, status.getId());
                    statement.bindLong(++index, listId);
                    statement.bindString(++index, status.getText());
                    statement.bindString(++index, status.getUser().getScreenName());
                    statement.bindString(++index, status.getUser().getName());
                    statement.bindLong(++index, status.getCreatedAt().getTime());
                    statement.bindString(++index, status.getUser().getProfileImageURL());
                }
            });
}

From source file:com.twitt4droid.data.dao.impl.sqlite.TimelineSQLiteDAO.java

License:Apache License

/** {@inheritDoc} */
@Override/*from  ww  w .  ja  v  a2s  .co m*/
public void save(final List<Status> statuses) {
    getSQLiteTemplate().batchExecute(
            String.format(getSqlString(R.string.twitt4droid_insert_status_sql), tableName),
            new SQLiteTemplate.BatchSQLiteStatementBinder() {

                @Override
                public int getBatchSize() {
                    return statuses.size();
                }

                @Override
                public void bindValues(SQLiteStatement statement, int i) {
                    Status status = statuses.get(i);
                    int index = 0;
                    statement.bindLong(++index, status.getId());
                    statement.bindString(++index, status.getText());
                    statement.bindString(++index, status.getUser().getScreenName());
                    statement.bindString(++index, status.getUser().getName());
                    statement.bindLong(++index, status.getCreatedAt().getTime());
                    statement.bindString(++index, status.getUser().getProfileImageURL());
                }
            });
}

From source file:com.twitter.tokyo.kucho.daemon.KuchoController.java

License:Apache License

@Override
public void onStatus(Status status) {
    String screenName = status.getUser().getScreenName();
    // lookup modules for the user's seat
    List<String> modules = seatingList.getVentilationModules(status.getUser().getScreenName());
    if (modules.size() == 0) {
        // user is not in the list. do nothing
        return;/*from   w  w  w . j  ava2  s.co m*/
    }

    String text = status.getText().toLowerCase().replaceAll("", "#");
    // does the tweet contain room name?
    for (String roomName : seatingList.getRooms()) {
        if (text.contains(roomName)) {
            modules = seatingList.getVentilationModulesIn(roomName);
            break;
        }
    }

    int degree = 2;
    if (text.matches(
            ".*(???|????|??|??|??|???|???|?|max|||???|?|?|????|??|?|"
                    + "|???|?|?||??|??|???|????|???|???|??|?|??"
                    + "|too|very|extremely|intensively).*")) {
        degree = 4;
    }
    for (String hot : HOT) {
        if (text.contains(hot)) {
            degree = degree * -1;
            break;
        }
    }

    String message = null;
    String imagePath = null;
    String powerfully = Math.abs(degree) == 4 ? "????" : "";
    if (degree < 0) {
        if (ehills.adjust(degree, modules)) {
            message = "@" + screenName + " " + powerfully + "?????? " + Message.getMessage();
            imagePath = "/atsui.jpg";
        } else {
            message = "@" + screenName + " ???????????";
            imagePath = "/kucho.jpg";
        }
    } else {
        if (ehills.adjust(degree, modules)) {
            message = "@" + screenName + "  " + powerfully + "?????? " + Message.getMessage();
            imagePath = "/samui.jpg";
        } else {
            message = "@" + screenName + " ??????????????";
            imagePath = "/kucho.jpg";
        }
    }
    System.out.println("messaage:" + message + " " + imagePath);
    try {
        if (!dryRun) {
            imagePath = "src/main/resources" + imagePath;
            if (!new File(".").getAbsolutePath().contains("kucho-daemon")) {
                imagePath = "kucho-daemon/" + imagePath;
            }
            File imageFile = new File(imagePath);
            if (imageFile.exists()) {
                TwitterFactory.getSingleton().updateStatus(
                        new StatusUpdate(message).media(imageFile).inReplyToStatusId(status.getId()));
            } else {
                TwitterFactory.getSingleton()
                        .updateStatus(new StatusUpdate(message).inReplyToStatusId(status.getId()));
            }
        }
    } catch (TwitterException e) {
        logger.error("failed to update status", e);
    }
}

From source file:com.utad.flume.source.TwitterSource.java

License:Apache License

/**
 * Start processing events. This uses the Twitter Streaming API to sample
 * Twitter, and process tweets./*  w  w  w. j a  v a 2  s .c o  m*/
 */
@Override
public void start() {
    // The channel is the piece of Flume that sits between the Source and Sink,
    // and is used to process events.
    final ChannelProcessor channel = getChannelProcessor();

    final Map<String, String> headers = new HashMap<String, String>();

    // The StatusListener is a twitter4j API, which can be added to a Twitter
    // stream, and will execute methods every time a message comes in through
    // the stream.
    StatusListener listener = new StatusListener() {
        // The onStatus method is executed every time a new tweet comes in.
        public void onStatus(Status status) {
            // The EventBuilder is used to build an event using the headers and
            // the raw JSON of a tweet
            logger.debug(status.getUser().getScreenName() + ": " + status.getText());

            headers.put("timestamp", String.valueOf(status.getCreatedAt().getTime()));
            Event event = EventBuilder.withBody(DataObjectFactory.getRawJSON(status).getBytes(), headers);
            List<Event> events = Arrays.asList(event);
            channel.processEventBatch(events);
        }

        // This listener will ignore everything except for new tweets
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
        }

        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
        }

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

        public void onException(Exception ex) {
        }

        public void onStallWarning(StallWarning warning) {
        }
    };

    logger.debug("Setting up Twitter sample stream using consumer key {} and" + " access token {}",
            new String[] { consumerKey, accessToken });
    // Set up the stream's listener (defined above),
    twitterStream.addListener(listener);

    // Set up a filter to pull out industry-relevant tweets
    if (keywords.length == 0) {
        logger.debug("Starting up Twitter sampling...");
        twitterStream.sample();
    } else {
        logger.debug("Starting up Twitter filtering...");

        FilterQuery query = new FilterQuery().track(keywords);
        twitterStream.filter(query);
    }
    super.start();
}

From source file:com.varaneckas.hawkscope.plugins.twitter.TwitterPlugin.java

License:Open Source License

/**
 * Lists twitter messages in a menu/*from  www  . j  av a2 s  . c  om*/
 * 
 * @param repMenu
 * @param messages
 */
private void listMessages(final Menu repMenu, final List<Status> messages) {
    try {
        for (final Status reply : messages) {
            String msg = reply.getUser().getName().concat(": ").concat(reply.getText().replaceAll("\\n", " "));
            MenuItem mi = new MenuItem(repMenu, SWT.PUSH);
            if (msg.length() > 80) {
                msg = msg.substring(0, 79).concat("...");
            }
            mi.setText(msg);
            mi.setImage(twitter.getUserImage(reply.getUser()));
            mi.addSelectionListener(new SelectionListener() {
                public void widgetDefaultSelected(SelectionEvent selectionevent) {
                    widgetSelected(selectionevent);
                }

                public void widgetSelected(SelectionEvent selectionevent) {
                    Program.launch(twitter.getBaseURL() + reply.getUser().getScreenName() + "/status/"
                            + reply.getId());
                }
            });
        }
    } catch (final Exception e) {
        log.warn("Failed listing replies", e);
    }
}

From source file:com.vodafone.twitter.service.TwitterService.java

License:Apache License

private boolean processStatus(Status status) {
    if (msgWithSameId(status.getId()) != null) {
        if (Config.LOGD)
            Log.i(LOGTAG, "processStatus() found msgWithSameId " + status.getId() + " - don't process");
        return false;
    }/*from w  ww . j  a va  2  s . c om*/

    boolean newMsgReceived = false;
    User user = status.getUser();
    String channelImageString = null;
    try {
        java.net.URI uri = user.getProfileImageURL().toURI();
        channelImageString = uri.toString();
    } catch (java.net.URISyntaxException uriex) {
        Log.e(LOGTAG, String.format("ConnectThread processStatus() URISyntaxException %s ex=%s",
                user.getProfileImageURL().toString(), uriex));
        errMsg = uriex.getMessage();
    }

    String title = status.getText();
    if (linkifyMessages) {
        title = linkify(title, null, true);
        // messageLink will contain the link-url
    }

    long timeMs = status.getCreatedAt().getTime();
    // make timeMs unique in our messageList
    while (findIdxOfMsgWithSameTimeMs(timeMs) >= 0)
        timeMs++;

    EntryTopic feedEntry = new EntryTopic(0, 0, user.getName(), title, null, messageLink, timeMs,
            status.getId(), channelImageString);
    feedEntry.shortName = user.getScreenName();
    synchronized (messageList) {
        // messageList is always sorted with the newest items on top
        int findIdxOfFirstOlder = findIdxOfFirstOlderMsg(feedEntry);
        if (findIdxOfFirstOlder < maxQueueMessages) {
            messageList.add(findIdxOfFirstOlder, feedEntry);
            newMsgReceived = true;
            totalNumberOfQueuedMessages++;
            if (activityPaused)
                numberOfQueuedMessagesSinceLastClientActivity++;

            // debug: for every regular msg, create 5 additional dummy messages
            //for(int i=1; i<=5; i++) {
            //  feedEntry = new EntryTopic(0,                                   // region
            //                             0,                                   // prio
            //                             "dummy",
            //                             "test message "+i,
            //                             null,                                // description
            //                             messageLink,
            //                             timeMs+i*100,
            //                             status.getId()+i,                    // todo: make sure the id was ot yet stored in messageList
            //                             channelImageString);                 // todo: must make use of this in MyWebView/JsObject/script.js
            //  messageList.add(findIdxOfFirstOlder,feedEntry);
            //  totalNumberOfQueuedMessages++;
            //  if(activityPaused)
            //    numberOfQueuedMessagesSinceLastClientActivity++;
            //}

            // if there are now more than 'maxQueueMessages' entrys in the queue, remove the oldest...
            while (messageList.size() > maxQueueMessages)
                messageList.removeLast();
        } else {
            if (Config.LOGD)
                Log.i(LOGTAG, "processStatus() not findIdxOfFirstOlder<maxQueueMessages - don't process");
        }
    }
    return newMsgReceived;
}

From source file:com.vti.managers.TwitterManager.java

License:Apache License

/**
 * Get homeline of the user//from  ww  w .  j a  va  2  s . co  m
 * 
 * @return List<Twits>
 */
public List<Twit> getSocialFeed() {
    List<Twit> twits = null;
    try {
        // User user = twitter.verifyCredentials();
        final List<Status> statues = twitter.getHomeTimeline();
        twits = new ArrayList<Twit>(statues.size());

        long oneDayAgo = System.currentTimeMillis() - Constants.THIRTY_MINUTE * 48;
        for (Status status : statues) {
            // only return tweets from VTI accounts and that are not old than 1 day
            if (status.getUser().getName().toLowerCase().startsWith("vti_")
                    && status.getCreatedAt().getTime() > oneDayAgo) {
                //Log.d(TwitterManager.class.getSimpleName(), status.getUser().getName() + "  " + status.getText());
                twits.add(new Twit(status.getId(), status.getCreatedAt().getTime(), status.getUser().getName(),
                        status.getUser().getProfileImageURL().toString(), status.getText()));
            }
        }
    } catch (Exception e) {
        Log.d(TAG, Log.stack2string(e));
    }
    return twits;

}