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:jp.wda.azeda.core.daemons.impl.UserCrawlerImpl.java

License:Apache License

/**
 *
 *//*from   ww w  . j  a v  a 2 s .c o m*/
@Aspect("aop.requiredTx")
public void crawl() throws TwitterException {
    StoredAccessToken storedAccessToken = accessTokensDao.getAccessTokenByUserID(userID);
    if (storedAccessToken == null) {
        return;
    }
    if (!alive) {
        return;
    }
    log.debug("crawl user retweets!!");

    Twitter twitter = new TwitterFactory().getInstance();
    AccessToken accessToken = new AccessToken(storedAccessToken.getAccessToken(),
            storedAccessToken.getAccessTokenSecret());
    twitter.setOAuthAccessToken(accessToken);

    List<Status> retweets = twitter.getRetweetsOfMe();
    if (!alive) {
        return;
    }

    List<RetweetedTweet> registered = dao.getAll(userID,
            new Timestamp(System.currentTimeMillis() - 365 * 24 * 60 * 60 * 1000L));
    List<Long> registeredIDs = new ArrayList<Long>();
    for (RetweetedTweet t : registered) {
        registeredIDs.add(t.getTweetID());
    }
    if (!alive) {
        return;
    }

    List<RetweetedTweet> dtos = new ArrayList<RetweetedTweet>();
    long oldest = System.currentTimeMillis() - expired * 24 * 60 * 60 * 1000L;
    for (Status s : retweets) {
        if (registeredIDs.contains(s.getId())) {
            continue;
        }
        if (s.getCreatedAt().getTime() < oldest) {
            continue;
        }

        RetweetedTweet dto = new RetweetedTweet();
        dto.setTweetID(s.getId());
        dto.setUserID(userID);
        dto.setTweettext(s.getText());
        dto.setCreatedat(new Timestamp(s.getCreatedAt().getTime()));
        dtos.add(dto);
    }
    if (!alive) {
        return;
    }
    dao.insertBatch(dtos);
}

From source file:Jums.AllAPI.java

public int TweetCount(String word) {
    int i = 0;/*w  w  w  .j a va 2 s.co m*/
    try {
        Query query = new Query(word);
        query.setCount(100);
        Date date = this.SetDate();
        query.setSince(this.SetSDF());
        QueryResult result = this.tw.search(query);
        for (Status status : result.getTweets()) {
            if (date.compareTo(status.getCreatedAt()) < 0) {
                i++;
            }
        }
    } catch (TwitterException te) {
        System.out.println(te.getMessage());
    } catch (Exception e) {
        System.out.println(e.getMessage());
    }
    return i;
}

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

License:Apache License

public static Twit createTwit(Status status) {
    Twit twit = new Twit();
    twit.setId(status.getId());/*  www . j  ava  2s. c o  m*/
    twit.setUsername(status.getUser().getName());
    twit.setText(status.getText());
    twit.setCreatedAt(status.getCreatedAt());
    return twit;
}

From source file:main.TwitterController.java

License:Open Source License

public void listMentions() throws TwitterException {
    int counter = 0;
    List<Status> mentions = twitter.getMentions();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Iterator<Status> iterator = mentions.iterator();
    while (iterator.hasNext()) {
        Status s = iterator.next();
        System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + printUser(s.getUser()) + ": "
                + s.getText());/* ww w  .  ja  v  a 2 s . c o  m*/
        if (counter % 10 == 0) {
            System.out.print("Hit [Enter] to continue, or type q to break: ");
            String str = null;
            try {
                str = in.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (str.length() > 0 && (str.charAt(0) == 'Q' || str.charAt(0) == 'q'))
                return;
        }
    }
}

From source file:main.TwitterController.java

License:Open Source License

public void getMyTimeline() throws TwitterException {
    int counter = 0;
    List<Status> statusList = twitter.getUserTimeline();
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    Iterator<Status> iterator = statusList.iterator();
    while (iterator.hasNext()) {
        Status s = iterator.next();
        System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + s.getText());
        if (counter == 10) {
            System.out.print("Hit [Enter] to continue, or type q to break: ");
            String str = null;//from w w w . j a v a2s. com
            try {
                str = in.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (str.length() > 0 && (str.charAt(0) == 'Q' || str.charAt(0) == 'q'))
                return;
        }
    }
}

From source file:main.TwitterController.java

License:Open Source License

public void getOthersTimeline(String uname) throws TwitterException {
    User user = twitter.getUserDetail(uname);
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println(printUser(user));

    List<Status> statusList = twitter.getUserTimeline(uname);
    int counter = 0;

    Iterator<Status> iterator = statusList.iterator();
    while (iterator.hasNext()) {
        Status s = iterator.next();
        System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + s.getText());
        if (counter % 10 == 0) {
            System.out.print("Hit [Enter] to continue, or type q to break: ");
            String str = null;/* www  .ja  v  a2  s  .c o m*/
            try {
                str = in.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (str.length() > 0 && (str.charAt(0) == 'Q' || str.charAt(0) == 'q'))
                return;
        }
    }
}

From source file:main.TwitterController.java

License:Open Source License

public void getTimeline() throws TwitterException {
    List<Status> statusList = null;
    int counter = 0;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    statusList = twitter.getFriendsTimeline();

    Iterator<Status> iterator = statusList.iterator();
    while (iterator.hasNext()) {
        Status s = iterator.next();
        System.out.println(++counter + " [" + s.getCreatedAt().toString() + "] " + printUser(s.getUser()) + ": "
                + s.getText());/*from  w ww.  ja va  2  s .com*/
        if (counter % 10 == 0) {
            System.out.print("Hit [Enter] to continue, or type q to break: ");
            String str = null;
            try {
                str = in.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (str.length() > 0 && (str.charAt(0) == 'Q' || str.charAt(0) == 'q'))
                return;
        }
    }
}

From source file:mapper.TweetDataMapper.java

/**
* Transform a {@link Status} into an {@link Tweet}.
*
* @param status Object to be transformed.
* @return {@link Tweet}.// w  w  w  .  j a v  a 2  s.  c om
*/
@Override
public Tweet transform(Status status) {
    if (status == null) {
        throw new IllegalArgumentException("Cannot transform a null value");
    }
    Tweet tweet = new Tweet();
    tweet.setCreateAt(status.getCreatedAt());
    tweet.setLang(status.getLang());
    if (status.getGeoLocation() != null) {
        tweet.setLat(status.getGeoLocation().getLatitude());
        tweet.setLon(status.getGeoLocation().getLongitude());
    }
    tweet.setReTweetCount(status.getRetweetCount());
    tweet.setText(status.getText());
    return tweet;

}

From source file:moderation.Moderate.java

public List getTwitterpost() {

    List posts = new ArrayList();
    try {/*from  w w  w .  j  a v  a 2 s.c om*/
        List savedpost = getSavedList(album_id);
        String tagname = this.hash;
        Twitter twitter = setting.TwitterToken.twitterObject();
        Query query = new Query(tagname);
        query.setCount(50);
        QueryResult result;
        result = twitter.search(query);
        List<Status> tweets = result.getTweets();
        for (Status tweet : tweets) {
            System.out.println("\n\n\n" + tweet);
            PostModel post = new PostModel();
            post.setAlbum_id(this.album_id);
            if (savedpost.contains(tweet.getId()))
                post.setStatus("old");
            else
                post.setStatus("new");
            post.setPost_id("" + tweet.getId());
            post.setSender_name(URLEncoder.encode(tweet.getUser().getScreenName(), "UTF-8"));
            post.setCaption_text(URLEncoder.encode(tweet.getText(), "UTF-8"));
            post.setSender_pic(tweet.getUser().getProfileImageURL());
            post.setSender_id("" + tweet.getUser().getId());

            for (MediaEntity mediaEntity : tweet.getMediaEntities()) {
                post.setImage_standard(mediaEntity.getMediaURL());
                post.setImage_low(mediaEntity.getMediaURL());
            }
            post.setPost_time(tweet.getCreatedAt().toString());
            post.setType("twitter_post");
            post.setLink(null);
            post.setParam("post_id=" + post.getPost_id() + "&album_id=" + post.getAlbum_id() + "&type="
                    + post.getType() + "&post_time=" + post.getPost_time() + "&link=" + post.getLink()
                    + "&pic_low=" + post.getImage_low() + "&pic_standard=" + post.getImage_standard()
                    + "&post_message=" + post.getCaption_text() + "&sender_name=" + post.getSender_name()
                    + "&sender_id=" + post.getSender_id() + "&sender_pic=" + post.getSender_pic());

            posts.add(post);

        }
        this.twitternext = result.nextQuery();

    } catch (Exception e) {
        System.err.println("Exception occure in getTwitter " + e);
    }

    return posts;
}

From source file:module.ihm.MainFrameInitializer.java

public void initJList() {
    JList jList = (JList) application.getMainFrameJComponent("jListTweet");
    DefaultListModel model = new DefaultListModel();
    jList.setCellRenderer(new ListCellRenderer() {

        @Override/*from  ww w  .  j  av  a2 s .  c  o m*/
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            JLabel renderer = (JLabel) new DefaultListCellRenderer().getListCellRendererComponent(list, value,
                    index, isSelected, cellHasFocus);
            if (value instanceof Status) {
                Status s = (Status) value;
                renderer.setForeground(new Color(0, 51, 102));
                try {
                    renderer.setIcon(new ImageIcon(new URL(s.getUser().getProfileImageURL().toString())));
                } catch (MalformedURLException ex) {
                    Logger.getLogger(MainFrameInitializer.class.getName()).log(Level.SEVERE, null, ex);
                }
                SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

                renderer.setText("<html><b>" + s.getUser().getName() + " @" + s.getUser().getScreenName()
                        + "</b><br>" + s.getText() + "<br>" + "Ecrit le " + dateformat.format(s.getCreatedAt())
                        + "<br><br> </html>");
            }
            if (value instanceof twitter4j.User) {
                twitter4j.User u = (twitter4j.User) value;
                try {
                    renderer.setIcon(new ImageIcon(new URL(u.getProfileImageURL().toString())));
                } catch (MalformedURLException ex) {
                    Logger.getLogger(MainFrameInitializer.class.getName()).log(Level.SEVERE, null, ex);
                }

                renderer.setText(u.getName() + " @" + u.getScreenName());
            }
            return renderer;
        }
    });
    jList.addMouseListener(new MouseListener() {

        @Override
        public void mouseClicked(MouseEvent e) {
            JList jList = (JList) application.getMainFrameJComponent("jListTweet");
            if (jList.getSelectedValue() instanceof Status) {
                Status s = (Status) jList.getSelectedValue();
                //                  System.out.println(s);
                PandaProdButton button = (PandaProdButton) hsJcomponent.get("pandaProdButtonRetweet");
                button.setVisible(true);

            } else if (jList.getSelectedValue() instanceof twitter4j.User) {
                twitter4j.User s = (twitter4j.User) jList.getSelectedValue();
                //                    System.out.println(s);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseEntered(MouseEvent e) {
        }

        @Override
        public void mouseExited(MouseEvent e) {

        }
    });

    for (Status s : user.getListOfTweet()) {
        model.addElement(s);
    }

    jList.setModel(model);

}