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;
  }
Exemple #2
0
  /**
   * 获取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();
    }
  }
 /** @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();
   }
 }