Example usage for twitter4j Status getCreatedAt

List of usage examples for twitter4j Status getCreatedAt

Introduction

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

Prototype

Date getCreatedAt();

Source Link

Document

Return the created_at

Usage

From source file:demo.UserInfo.java

License:Apache License

public static void main(String[] args) throws IOException, TwitterException {
    //?/*from w  ww  . j  a va2 s  .  c o m*/
    Configuration configuration = new ConfigurationBuilder().setOAuthConsumerKey(CONSUMER_KEY)
            .setOAuthConsumerSecret(CONSUMER_SECRET).setOAuthAccessToken(ACCESS_TOKEN)
            .setOAuthAccessTokenSecret(ACCESS_TOKEN_SECRET).build();
    Twitter tw = new TwitterFactory(configuration).getInstance();
    String screenName = "";

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    System.out.print("????ScreenName???????!! ex)masason : ");
    screenName = br.readLine();
    //String screenName = "masason";//masason
    try {
        //?&
        User user = tw.showUser(screenName);
        System.out.println("???");
        System.out.println("User ID : " + user.getId());
        System.out.println("ScreenName : " + user.getScreenName());
        System.out.println("User's Name : " + user.getName());
        System.out.println("Number of Followers : " + user.getFollowersCount());
        System.out.println("Number of Friends : " + user.getFriendsCount());
        System.out.println("Language : " + user.getLang());
        //?
        Status status = user.getStatus();
        System.out.println("???");
        System.out.println("User Created : " + status.getCreatedAt());
        System.out.println("Status ID : " + status.getId());
        System.out.println(status.getSource());
        System.out.println("Tweet" + status.getText());

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:dhbw.clippinggorilla.external.twitter.TwitterUtils.java

private static Article fillArticle(Status status) {
    Article article = new Article();
    article.setTitle(status.getUser().getName());
    article.setDescription(status.getText());
    article.setBody(status.getText());/*from  ww  w. ja  v a  2 s.co m*/
    article.setSource(SourceUtils.TWITTER);
    for (MediaEntity mediaEntity : status.getMediaEntities()) {
        if (!mediaEntity.getType().equals("video")) {
            article.setUrlToImage(mediaEntity.getMediaURL());
            break;
        }
    }
    if (article.getUrlToImage().isEmpty()) {
        article.setUrlToImage(status.getUser().getBiggerProfileImageURL());
    }
    article.setUrl("https://twitter.com/" + status.getUser().getScreenName() + "/status/" + status.getId());
    article.setId(status.getId() + "");
    article.setAuthor("@" + status.getUser().getScreenName());
    Date date = status.getCreatedAt();
    Instant instant = Instant.ofEpochMilli(date.getTime());
    LocalDateTime createdAt = LocalDateTime.ofInstant(instant, ZoneOffset.UTC);
    article.setPublishedAt(createdAt.toString());
    return article;
}

From source file:druid.examples.twitter.TwitterSpritzerFirehoseFactory.java

License:Open Source License

@Override
public Firehose connect() throws IOException {
    final ConnectionLifeCycleListener connectionLifeCycleListener = new ConnectionLifeCycleListener() {
        @Override/*w  ww .  jav  a  2s.com*/
        public void onConnect() {
            log.info("Connected_to_Twitter");
        }

        @Override
        public void onDisconnect() {
            log.info("Disconnect_from_Twitter");
        }

        /**
         * called before thread gets cleaned up
         */
        @Override
        public void onCleanUp() {
            log.info("Cleanup_twitter_stream");
        }
    }; // ConnectionLifeCycleListener

    final TwitterStream twitterStream;
    final StatusListener statusListener;
    final int QUEUE_SIZE = 2000;
    /** This queue is used to move twitter events from the twitter4j thread to the druid ingest thread.   */
    final BlockingQueue<Status> queue = new ArrayBlockingQueue<Status>(QUEUE_SIZE);
    final LinkedList<String> dimensions = new LinkedList<String>();
    final long startMsec = System.currentTimeMillis();

    dimensions.add("htags");
    dimensions.add("lang");
    dimensions.add("utc_offset");

    //
    //   set up Twitter Spritzer
    //
    twitterStream = new TwitterStreamFactory().getInstance();
    twitterStream.addConnectionLifeCycleListener(connectionLifeCycleListener);
    statusListener = new StatusListener() { // This is what really gets called to deliver stuff from twitter4j
        @Override
        public void onStatus(Status status) {
            // time to stop?
            if (Thread.currentThread().isInterrupted()) {
                throw new RuntimeException("Interrupted, time to stop");
            }
            try {
                boolean success = queue.offer(status, 15L, TimeUnit.SECONDS);
                if (!success) {
                    log.warn("queue too slow!");
                }
            } catch (InterruptedException e) {
                throw new RuntimeException("InterruptedException", e);
            }
        }

        @Override
        public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
            //log.info("Got a status deletion notice id:" + statusDeletionNotice.getStatusId());
        }

        @Override
        public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
            // This notice will be sent each time a limited stream becomes unlimited.
            // If this number is high and or rapidly increasing, it is an indication that your predicate is too broad, and you should consider a predicate with higher selectivity.
            log.warn("Got track limitation notice:" + numberOfLimitedStatuses);
        }

        @Override
        public void onScrubGeo(long userId, long upToStatusId) {
            //log.info("Got scrub_geo event userId:" + userId + " upToStatusId:" + upToStatusId);
        }

        @Override
        public void onException(Exception ex) {
            ex.printStackTrace();
        }

        @Override
        public void onStallWarning(StallWarning warning) {
            System.out.println("Got stall warning:" + warning);
        }
    };

    twitterStream.addListener(statusListener);
    twitterStream.sample(); // creates a generic StatusStream
    log.info("returned from sample()");

    return new Firehose() {

        private final Runnable doNothingRunnable = new Runnable() {
            public void run() {
            }
        };

        private long rowCount = 0L;
        private boolean waitIfmax = (maxEventCount < 0L);
        private final Map<String, Object> theMap = new HashMap<String, Object>(2);
        // DIY json parsing // private final ObjectMapper omapper = new ObjectMapper();

        private boolean maxTimeReached() {
            if (maxRunMinutes <= 0) {
                return false;
            } else {
                return (System.currentTimeMillis() - startMsec) / 60000L >= maxRunMinutes;
            }
        }

        private boolean maxCountReached() {
            return maxEventCount >= 0 && rowCount >= maxEventCount;
        }

        @Override
        public boolean hasMore() {
            if (maxCountReached() || maxTimeReached()) {
                return waitIfmax;
            } else {
                return true;
            }
        }

        @Override
        public InputRow nextRow() {
            // Interrupted to stop?
            if (Thread.currentThread().isInterrupted()) {
                throw new RuntimeException("Interrupted, time to stop");
            }

            // all done?
            if (maxCountReached() || maxTimeReached()) {
                if (waitIfmax) {
                    // sleep a long time instead of terminating
                    try {
                        log.info("reached limit, sleeping a long time...");
                        sleep(2000000000L);
                    } catch (InterruptedException e) {
                        throw new RuntimeException("InterruptedException", e);
                    }
                } else {
                    // allow this event through, and the next hasMore() call will be false
                }
            }
            if (++rowCount % 1000 == 0) {
                log.info("nextRow() has returned %,d InputRows", rowCount);
            }

            Status status;
            try {
                status = queue.take();
            } catch (InterruptedException e) {
                throw new RuntimeException("InterruptedException", e);
            }

            HashtagEntity[] hts = status.getHashtagEntities();
            if (hts != null && hts.length > 0) {
                List<String> hashTags = Lists.newArrayListWithExpectedSize(hts.length);
                for (HashtagEntity ht : hts) {
                    hashTags.add(ht.getText());
                }

                theMap.put("htags", Arrays.asList(hashTags.get(0)));
            }

            long retweetCount = status.getRetweetCount();
            theMap.put("retweet_count", retweetCount);
            User user = status.getUser();
            if (user != null) {
                theMap.put("follower_count", user.getFollowersCount());
                theMap.put("friends_count", user.getFriendsCount());
                theMap.put("lang", user.getLang());
                theMap.put("utc_offset", user.getUtcOffset()); // resolution in seconds, -1 if not available?
                theMap.put("statuses_count", user.getStatusesCount());
            }

            return new MapBasedInputRow(status.getCreatedAt().getTime(), dimensions, theMap);
        }

        @Override
        public Runnable commit() {
            // ephemera in, ephemera out.
            return doNothingRunnable; // reuse the same object each time
        }

        @Override
        public void close() throws IOException {
            log.info("CLOSE twitterstream");
            twitterStream.shutdown(); // invokes twitterStream.cleanUp()
        }
    };
}

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
 * //from   w  w  w .  j  av  a 2  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:edu.cmu.geolocator.coder.utils.JSON2Tweet.java

License:Apache License

public JSONTweet readLine() {
    String line;/*from   w  w  w  .jav  a  2s.  c o  m*/
    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;
    try {//from  w w  w . j av a 2  s.c o  m
        // 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:edu.uci.ics.asterix.external.util.TweetProcessor.java

License:Apache License

public AMutableRecord processNextTweet(Status tweet) {
    User user = tweet.getUser();//www.  j av  a  2  s . c  o m
    ((AMutableString) mutableUserFields[0]).setValue(getNormalizedString(user.getScreenName()));
    ((AMutableString) mutableUserFields[1]).setValue(getNormalizedString(user.getLang()));
    ((AMutableInt32) mutableUserFields[2]).setValue(user.getFriendsCount());
    ((AMutableInt32) mutableUserFields[3]).setValue(user.getStatusesCount());
    ((AMutableString) mutableUserFields[4]).setValue(getNormalizedString(user.getName()));
    ((AMutableInt32) mutableUserFields[5]).setValue(user.getFollowersCount());

    ((AMutableString) mutableTweetFields[0]).setValue(tweet.getId() + "");

    for (int i = 0; i < 6; i++) {
        ((AMutableRecord) mutableTweetFields[1]).setValueAtPos(i, mutableUserFields[i]);
    }
    if (tweet.getGeoLocation() != null) {
        ((AMutableDouble) mutableTweetFields[2]).setValue(tweet.getGeoLocation().getLatitude());
        ((AMutableDouble) mutableTweetFields[3]).setValue(tweet.getGeoLocation().getLongitude());
    } else {
        ((AMutableDouble) mutableTweetFields[2]).setValue(0);
        ((AMutableDouble) mutableTweetFields[3]).setValue(0);
    }
    ((AMutableString) mutableTweetFields[4]).setValue(getNormalizedString(tweet.getCreatedAt().toString()));
    ((AMutableString) mutableTweetFields[5]).setValue(getNormalizedString(tweet.getText()));

    for (int i = 0; i < 6; i++) {
        mutableRecord.setValueAtPos(i, mutableTweetFields[i]);
    }

    return mutableRecord;

}

From source file:es.portizsan.twitrector.tasks.TweetSearchTask.java

License:Open Source License

@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
    long before = System.currentTimeMillis() - (1000 * 60 * 15);
    try {// www  .  j  a  va  2 s . c om
        List<Twitrector> trl = new TwitrectorService().getTwitrectors();
        if (trl == null || trl.isEmpty()) {
            logger.log(Level.WARNING, "No Twitrectors found!!!!!");
            return;
        }
        for (Twitrector tr : trl) {
            logger.info("Searching for :" + tr.getQuery());
            String search = tr.getQuery();
            Twitter twitter = new TwitterService().getTwitterInstance();
            Query query = new Query(search);
            query.setLocale("es");
            query.setCount(100);
            if (tr.getLocation() != null) {
                GeoLocation location = new GeoLocation(tr.getLocation().getLatitude(),
                        tr.getLocation().getLongitude());
                Unit unit = Unit.valueOf(tr.getLocation().getUnit().name());
                query.setGeoCode(location, tr.getLocation().getRadius(), unit);
            }
            QueryResult result;
            do {
                result = twitter.search(query);
                List<Status> tweets = result.getTweets();
                for (Status tweet : tweets) {
                    if (tweet.getCreatedAt().getTime() < before)
                        continue;
                    Queue queue = QueueFactory.getQueue("default");
                    queue.add(TaskOptions.Builder.withUrl("/tasks/tweetReply")
                            .param("statusId", String.valueOf(tweet.getId()))
                            .param("message", "@" + tweet.getUser().getScreenName() + " "
                                    + String.valueOf(tr.getResponse())));

                    logger.info("@" + tweet.getUser().getScreenName() + " - " + tweet.getText());
                }
            } while ((query = result.nextQuery()) != null);
        }
    } catch (TwitterException te) {
        logger.log(Level.WARNING, "Failed to search tweets: ", te);
    }
}

From source file:ezbake.training.TweetIngestParser.java

License:Apache License

private Tweet convertToTweet(Status status) {
    Tweet tweet = new Tweet();
    tweet.setTimestamp(status.getCreatedAt().getTime());
    tweet.setId(status.getId());//  w  ww  . j a  va 2s . c  o m
    tweet.setText(status.getText());
    tweet.setUserId(status.getUser().getId());
    tweet.setUserName(status.getUser().getName());
    tweet.setIsFavorite(status.isFavorited());
    tweet.setIsRetweet(status.isRetweet());
    if (status.getGeoLocation() != null) {
        tweet.setGeoLocation(
                new Coordinate(status.getGeoLocation().getLatitude(), status.getGeoLocation().getLongitude()));
    }
    return tweet;
}

From source file:fr.ybo.transportsrennes.adapters.TwitterAdapter.java

License:Open Source License

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;/*  w  w w.ja v  a  2 s  . c o  m*/
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.onetwitter, null);
        holder = new ViewHolder();
        holder.twitter = (TextView) convertView.findViewById(R.id.twitter);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    Status status = allStatus.get(position);
    holder.twitter.setText(SDF.format(status.getCreatedAt()) + status.getText());
    return convertView;
}