コード例 #1
0
  public static boolean getComments()
      throws ClassNotFoundException, SQLException, InterruptedException {
    boolean isDone = true;
    System.out.println(" Will connect to the database and get status.......");
    Connection conComments = PublicMethods.getConnection();
    System.out.println(
        " Okay the connnection to mysql has been established..we are going to select id from status.....");
    java.sql.Statement stmt =
        conComments.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
    ResultSet rset =
        stmt.executeQuery("select id, commentCounts from status where isDone = false limit 100");
    int pageNum = 1;
    int commentCounts = 0;
    long statusId = (long) 0;
    while (rset.next()) {
      isDone = false;
      statusId = rset.getLong(1);
      commentCounts = rset.getInt(2);
      System.out.println("commentCounts: " + commentCounts);
      // Thread.sleep(2000);
      if (commentCounts == 0) {
        PublicMethods.UpdateStatusComments(conComments, statusId);
        // continue;
      } else {
        try {
          Paging pag = new Paging();
          pag.setCount(100);
          pageNum = 1;
          do {
            pag.setPage(pageNum);
            List<Comment> comments = PublicMethods.weibo.getComments(statusId + "", pag);
            // List<Comment> comments = PublicMethods.weibo.getComments("3343531616094195",pag);

            pageNum++;
            if (comments.isEmpty()) {
              // Thread.sleep(4700);
              break;
            } else {
              for (Comment comment : comments) {
                PublicMethods.InsertCommentsSql(conComments, comment, statusId);
                commentCounts--;
              }
              if (commentCounts <= 100) {
                break;
              }
            }
            // Thread.sleep(5700);
          } while (true);
          PublicMethods.UpdateStatusComments(conComments, statusId);
        } catch (WeiboException e) {
          e.printStackTrace();
        }
      }
    }
    conComments.close();
    return isDone;
  }
コード例 #2
0
  /**
   * @param weibo
   * @param id
   * @return the latest retweet for tweet id with maximum number of Countmax
   * @throws WeiboException
   */
  public ArrayList<Status> getRepostTimeline(Weibo weibo, String id) throws WeiboException {
    int Countmax = 200;

    Paging paging = new Paging();
    paging.setCount(Countmax);
    paging.setSinceId(3363472209835882L);
    ArrayList<Status> statuses = (ArrayList<Status>) weibo.getreposttimeline(id, paging);
    /*
     * for(int i = 2; i<4; i++){ if(statuses.size()==200*(i-1)){
     * paging.setPage(i); statuses.addAll(weibo.getreposttimeline(id,
     * paging)); }else{ break; } }
     */

    return statuses;
  }
コード例 #3
0
  private ArrayList<Status> getUserReposts(Weibo weibo, String id) throws WeiboException {
    // TODO Auto-generated method stub
    int Countmax = 200;

    Paging paging = new Paging();
    paging.setCount(Countmax);
    paging.setSinceId(3363472209835882L);
    ArrayList<Status> statuses = (ArrayList<Status>) weibo.getrepostbyme(id, paging);
    /*
     * for(int i = 2; i<4; i++){ if(statuses.size()==200*(i-1)){
     * paging.setPage(i); statuses.addAll(weibo.getreposttimeline(id,
     * paging)); }else{ break; } }
     */

    return statuses;
  }
コード例 #4
0
ファイル: GetTags.java プロジェクト: WangMJ/workspace
  /**
   * 获取tags;
   *
   * @param args args[0]和args[1]为通过GetToken.java获取到的accesstoken和accesstoken secret args[2]为获取用户的Id
   */
  public static void main(String[] args) {
    System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
    System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
    try {
      Weibo weibo = new Weibo();
      weibo.setToken(args[0], args[1]);
      Paging paging = new Paging();
      paging.setCount(20);
      paging.setPage(1);
      List<Tag> gettags = weibo.getTags(args[2], paging);
      for (Tag status : gettags) {
        System.out.println(status.toString());
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
コード例 #5
0
ファイル: getTrendsWeekly.java プロジェクト: WangMJ/workspace
 /** @param args */
 public static void main(String[] args) {
   // TODO Auto-generated method stub
   System.setProperty("weibo4j.oauth.consumerKey", Weibo.CONSUMER_KEY);
   System.setProperty("weibo4j.oauth.consumerSecret", Weibo.CONSUMER_SECRET);
   Paging paging = new Paging();
   paging.setCount(20);
   paging.setPage(1);
   try {
     Weibo weibo = new Weibo();
     weibo.setToken(args[0], args[1]);
     List<Trends> trendsWeekly = weibo.getTrendsWeekly(0);
     System.out.println("=======按周返回热门话题=======");
     System.out.println(trendsWeekly);
   } catch (WeiboException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
 }