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:Read_data.java

/**
 * @param args the command line arguments
 * @throws twitter4j.TwitterException/*from   w  ww . ja  va 2s  .  c  o m*/
 * @throws java.io.FileNotFoundException
 */
public static void main(String[] args) throws TwitterException, FileNotFoundException, IOException {
    // TODO code application logic here

    ConfigurationBuilder cb = new ConfigurationBuilder();
    cb.setDebugEnabled(true).setOAuthConsumerKey(customer_key).setOAuthConsumerSecret(customer_secret)
            .setOAuthAccessToken(access_token).setOAuthAccessTokenSecret(access_token_secret);

    TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();

    StatusListener statusListener = new StatusListener() {

        @Override
        public void onStatus(Status status) {

            //get the place if it is not null
            if (status.getPlace() != null) {

                try {

                    String place = status.getPlace().getName();

                    System.out.println("Place: " + place + "\t\t\t" + "Tweet: " + status.getText());

                    Thread.sleep(1000);
                } catch (InterruptedException ex) {
                    Logger.getLogger(Read_data.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }

        @Override

        public void onDeletionNotice(StatusDeletionNotice sdn) {
            System.out.print("");
        }

        @Override
        public void onTrackLimitationNotice(int i) {
            System.out.print("");
        }

        @Override
        public void onScrubGeo(long l, long l1) {
            System.out.print("");
        }

        @Override
        public void onStallWarning(StallWarning sw) {
            System.out.println(sw);
        }

        @Override
        public void onException(Exception ex) {
            System.out.println(ex);
        }
    };

    FilterQuery fq = new FilterQuery();

    //Stream tweets with these keywords. Replace for your tweets that you are looking for.
    String keywords[] = { "lol", "lls", "lmao", "llf" };

    fq.track(keywords);

    twitterStream.addListener(statusListener);
    twitterStream.filter(fq);

    try {
        synchronized (lock) {
            lock.wait();
        }
    } catch (InterruptedException e) {
        System.out.println(e);
    }
    System.out.println("returning statuses");
    // twitterStream.shutdown();
}

From source file:Streamer.java

@Override
public void onStatus(Status status) {
    if ((status.getPlace() != null) && !users.contains((status.getUser().getName()))
            && trending.validate(status)) {
        data.add(status);/*w  ww  . ja va2  s . c  om*/
        users.add(status.getUser().getName());
    }
}

From source file:Trending.java

public boolean validate(Status stat) {
    for (int i = 0; i < size; i++) {
        if (stat.getPlace().getCountry().equals(countries[i])) {
            for (int n = 0; n < limit; n++) {
                if ((stat.getText().indexOf((bank[i][n]))) != -1) {
                    return true;
                }//from w  w  w .j ava 2 s.  c o m
            }
        }
    }
    return false;
}

From source file:Parser.java

public void setData(LinkedList<Status> data) {
    for (Status s : data) {
        for (int i = 0; i < countries.length; i++) {
            if (s.getPlace().getCountry().equalsIgnoreCase(countries[i])) {
                messages.get(i).add(s.getText());
            }//www  .ja v  a2 s  .  c om
        }
    }
}

From source file:ac.simons.tweetarchive.tweets.TweetStorageService.java

License:Apache License

@Transactional
public TweetEntity store(final Status status, final String rawContent) {
    final Optional<TweetEntity> existingTweet = this.tweetRepository.findOne(status.getId());
    if (existingTweet.isPresent()) {
        final TweetEntity rv = existingTweet.get();
        log.warn("Tweet with status {} already existed...", rv.getId());
        return rv;
    }//w  w  w . j  a v a 2 s .  com

    final TweetEntity tweet = new TweetEntity(status.getId(), status.getUser().getId(),
            status.getUser().getScreenName(), status.getCreatedAt().toInstant().atZone(ZoneId.of("UTC")),
            extractContent(status), extractSource(status), rawContent);
    tweet.setCountryCode(Optional.ofNullable(status.getPlace()).map(Place::getCountryCode).orElse(null));
    if (status.getInReplyToStatusId() != -1L && status.getInReplyToUserId() != -1L
            && status.getInReplyToScreenName() != null) {
        tweet.setInReplyTo(new InReplyTo(status.getInReplyToStatusId(), status.getInReplyToScreenName(),
                status.getInReplyToUserId()));
    }
    tweet.setLang(status.getLang());
    tweet.setLocation(Optional.ofNullable(status.getGeoLocation())
            .map(g -> new TweetEntity.Location(g.getLatitude(), g.getLongitude())).orElse(null));
    // TODO Handle quoted tweets
    return this.tweetRepository.save(tweet);
}

From source file:adapter.TwitterAllAdapter.java

License:Apache License

@Override
public void run() {

    while (true) {

        try {/*from w w  w . java 2s  .c  o  m*/
            Status status = this.messageQueue.take();

            Event event = new Event();

            int rtCount = 0;
            int fvCount = 0;

            if (status.isRetweet()) {

                rtCount = status.getRetweetedStatus().getRetweetCount();
                fvCount = status.getRetweetedStatus().getFavoriteCount();
            }

            Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(),
                    status.getUser().getScreenName(), status.getUser().getLang(),
                    status.getUser().getFollowersCount(), status.getUser().getFriendsCount(),
                    status.getHashtagEntities(), fvCount, rtCount, status.getGeoLocation());
            //status.getRetweetedStatus().getRetweetCount(), status.getGeoLocation());

            eventCount++;
            // cantReplicas: Cantidad de PEs que se quieren generar para el proximo operador
            // Nota: recuerden que la topologa no necesariamente deba ser de este estilo
            // tambin poda ser por un hash
            int cantReplicas = 10;
            event.put("levelTweet", Integer.class, eventCount % cantReplicas);

            event.put("id", Integer.class, eventCount);
            event.put("tweet", Tweet.class, tweet);

            getRemoteStream().put(event);

        } catch (Exception e) {
            logger.error("Error: " + e);
            logger.error("Error al crear evento");
        }

    }

}

From source file:adapter.TwitterKeywordsAdapter.java

License:Apache License

@Override
public void run() {

    while (true) {
        try {//from  w w w. j a va 2  s. c  o m

            Status status = this.messageQueue.take();

            Event event = new Event();

            Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(),
                    status.getUser().getScreenName(), status.getUser().getLang(),
                    status.getUser().getFollowersCount(), status.getUser().getFriendsCount(),
                    status.getHashtagEntities(), status.getFavoriteCount(), status.getRetweetCount(),
                    status.getGeoLocation());

            eventCount++;
            // cantReplicas: Cantidad de PEs que se quieren generar para el proximo operador
            // Nota: recuerden que la topologa no necesariamente deba ser de este estilo
            // tambin poda ser por un hash
            int cantReplicas = 10;
            event.put("levelTweet", Integer.class, eventCount % cantReplicas);
            event.put("id", Integer.class, eventCount);
            event.put("tweet", Tweet.class, tweet);

            getRemoteStream().put(event);

        } catch (Exception e) {
            logger.error("Error: " + e);
            logger.error("Error al crear evento");
        }

    }
}

From source file:adapter.TwitterLanguageAdapter.java

License:Apache License

@Override
public void run() {

    while (true) {
        try {//from   ww w .  jav  a2 s.c  o  m
            Status status = this.messageQueue.take();

            Event event = new Event();

            Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(),
                    status.getUser().getScreenName(), status.getUser().getLang(),
                    status.getUser().getFollowersCount(), status.getUser().getFriendsCount(),
                    status.getHashtagEntities(), status.getFavoriteCount(), status.getRetweetCount(),
                    status.getGeoLocation());

            eventCount++;
            // cantReplicas: Cantidad de PEs que se quieren generar para el proximo operador
            // Nota: recuerden que la topologa no necesariamente deba ser de este estilo
            // tambin poda ser por un hash
            int cantReplicas = 10;
            event.put("levelTweet", Integer.class, eventCount % cantReplicas);
            event.put("id", Integer.class, eventCount);
            event.put("tweet", Tweet.class, tweet);

            getRemoteStream().put(event);

        } catch (Exception e) {
            logger.error("Error: " + e);
            logger.error("Error al crear evento");
        }

    }
}

From source file:adapter.TwitterLocationAdapter.java

License:Apache License

@Override
public void run() {

    while (true) {
        try {/*from ww w .j  av  a2s .  co m*/
            Status status = this.messageQueue.take();

            Event event = new Event();

            Tweet tweet = new Tweet(status.getId(), status.getText(), status.getCreatedAt(), status.getPlace(),
                    status.getUser().getScreenName(), status.getUser().getLang(),
                    status.getUser().getFollowersCount(), status.getUser().getFriendsCount(),
                    status.getHashtagEntities(), status.getFavoriteCount(), status.getRetweetCount(),
                    status.getGeoLocation());

            eventCount++;
            // cantReplicas: Cantidad de PEs que se quieren generar para el
            // proximo operador
            // Nota: recuerden que la topologa no necesariamente deba ser
            // de este estilo
            // tambin poda ser por un hash
            int cantReplicas = 10;
            event.put("levelTweet", Integer.class, eventCount % cantReplicas);
            event.put("id", Integer.class, eventCount);
            event.put("tweet", Tweet.class, tweet);

            getRemoteStream().put(event);

        } catch (Exception e) {
            logger.error("Error: " + e);
            logger.error("Error al crear evento");
        }

    }
}

From source file:au.net.moon.tUtils.twitterFields.java

License:Open Source License

/**
 * Get a <CODE>HashMap</CODE> of tweet fields by parsing a twitter4j Status
 * /*  w w  w.  java  2  s.  c  o m*/
 * @param status
 *            the twitter4j Status object
 * @return the tweet fields as name, value pairs in a <CODE>HashMap</CODE>.
 */
public static HashMap<String, String> parseStatusObj(Status status) {
    HashMap<String, String> splitFields = new HashMap<String, String>();

    splitFields.put("createdAt", status.getCreatedAt().toString());
    splitFields.put("id", Long.toString(status.getId()));
    splitFields.put("text", status.getText());
    splitFields.put("source", status.getSource());
    splitFields.put("isTruncated", status.isTruncated() ? "1" : "0");
    splitFields.put("inReplyToStatusId", Long.toString(status.getInReplyToStatusId()));
    splitFields.put("inReplyToUserId", Long.toString(status.getInReplyToUserId()));
    splitFields.put("isFavorited", status.isFavorited() ? "1" : "0");
    splitFields.put("inReplyToScreenName", status.getInReplyToScreenName());
    if (status.getGeoLocation() != null) {
        splitFields.put("geoLocation", status.getGeoLocation().toString());
    } else {
        splitFields.put("geoLocation", "");
    }
    if (status.getPlace() != null) {
        splitFields.put("place", status.getPlace().toString());
    } else {
        splitFields.put("place", "");
    }
    splitFields.put("retweetCount", Long.toString(status.getRetweetCount()));
    splitFields.put("wasRetweetedByMe", status.isRetweetedByMe() ? "1" : "0");
    String contributors = "";
    if (status.getContributors() != null) {
        long[] tempContributors = status.getContributors();
        for (int i = 0; i < tempContributors.length; i++) {
            contributors += Long.toString(tempContributors[i]);
            if (i != tempContributors.length - 1) {
                contributors += ", ";
            }
        }
    }
    splitFields.put("contributors", contributors);
    splitFields.put("annotations", "");
    if (status.getRetweetedStatus() != null) {
        splitFields.put("retweetedStatus", "1");
    } else {
        splitFields.put("retweetedStatus", "0");
    }
    splitFields.put("userMentionEntities", status.getUserMentionEntities().toString());
    splitFields.put("urlEntities", status.getURLEntities().toString());
    splitFields.put("hashtagEntities", status.getHashtagEntities().toString());
    splitFields.put("user", status.getUser().toString());
    return splitFields;
}