예제 #1
0
 public MircString quotesToday() {
   quotes = ReadLog.load(file);
   LocalDate date = LocalDate.now();
   Long output = Statistics.dailyQuotes(quotes, date);
   System.out.println("quotecache output: " + output);
   String inputString = "Total quotes for today: " + output.toString();
   MircString string = MircString.of(inputString);
   return string;
 }
예제 #2
0
 public MircString lanCountdown() {
   LocalDateTime lan = LocalDateTime.of(2016, 4, 29, 18, 0, 0);
   LocalDateTime now = LocalDateTime.now();
   Long seconds = now.until(lan, ChronoUnit.SECONDS);
   int totalSeconds = (60 * 60 * 24 * 365 * 1000);
   BigDecimal bigSeconds = new BigDecimal(totalSeconds);
   BigDecimal secondsLeft = new BigDecimal(seconds);
   BigDecimal millennia = secondsLeft.divide(bigSeconds, 50, RoundingMode.HALF_UP);
   String inputString =
       "There are "
           + seconds.toString()
           + " seconds to LAN - you'd better be prepared for it, mofos. Or, if you're Ragnar, there are "
           + millennia
           + " millennia left.";
   if (seconds < 0) {
     seconds = Math.abs(seconds);
     inputString = "LAN has been running for " + seconds.toString() + " seconds! Kick ass!";
   }
   MircString mircString = MircString.of(inputString.toString());
   return mircString;
 }
예제 #3
0
  public static Result privateTweets(long last_id, String sort, int limit) {
    String result = "";
    List<Maopao> maopaos = null;
    Maopao maopao;
    MaopaoList maopaoList = new MaopaoList();

    String uid = session("id");

    if (uid == null || uid.length() == 0) {
      maopaoList.setCode(1000);
      return ok(Json.toJson(maopaoList));
    }

    String orderBy = "id";
    if ("hot".equals(sort)) {
      orderBy = "comment_count";
    }

    if (limit <= 0) {
      limit = 30;
    }

    Connection connection = null;
    Statement maopaoStatement = null;
    Statement commentStatement = null;
    Statement likeUserStatement = null;
    Statement ownerStatement = null;
    ResultSet maopaoResultSet = null;
    ResultSet commentResultSet = null;
    ResultSet likeUsersResultSet = null;
    ResultSet ownerResultSet = null;
    long tweetId;
    long maxTweetId;
    String where = " owner_id = " + uid + " ";
    String tableComment = "t_comment";
    String tableMaopao = "t_private_tweet";
    try {
      connection = DB.getConnection();
      maopaoStatement = connection.createStatement();
      commentStatement = connection.createStatement();
      likeUserStatement = connection.createStatement();
      ownerStatement = connection.createStatement();

      maxTweetId = DBUtil.queryMaxId(maopaoStatement, tableMaopao);

      if (last_id > maxTweetId) {
        maopaoResultSet =
            DBUtil.queryLastRecord(maopaoStatement, tableMaopao, where, orderBy, limit);
      } else {
        maopaoResultSet =
            DBUtil.queryLessLastRecord(
                maopaoStatement, tableMaopao, where, orderBy, "" + last_id, limit);
      }

      maopaos = new ArrayList<Maopao>();
      while (maopaoResultSet.next()) {
        maopao = new Maopao(maopaoResultSet);
        tweetId = Long.parseLong(maopao.id);

        String userSql = "SELECT * FROM t_user WHERE id = " + maopao.owner_id;
        ownerResultSet = ownerStatement.executeQuery(userSql);
        ownerResultSet.next();
        maopao.owner = new UserObject(ownerResultSet);

        if (maopao.likes > 0) {
          maopao.like_users = new ArrayList<UserObject>();

          String sql =
              "SELECT * FROM t_user WHERE id IN (SELECT owner_id FROM t_like_tweet WHERE tweet_id = '%s')";
          sql = String.format(sql, tweetId);
          likeUsersResultSet = likeUserStatement.executeQuery(sql);

          UserObject userObject;
          while (likeUsersResultSet.next()) {
            userObject = new UserObject(likeUsersResultSet);
            maopao.like_users.add(userObject);
            if (userObject.id.equals(session("id"))) {
              maopao.liked = true;
            }
          }
        }
        if (maopao.comments > 0) {
          maopao.comment_list = new ArrayList<BaseComment>();
          String sql =
              "SELECT t_user.id, t_user.name, t_user.head_url, t_comment.id, t_comment.content, t_comment.create_at, t_user.created_at "
                  + "FROM t_user INNER JOIN t_comment ON t_user.id = t_comment.owner_id WHERE tweet_id = %s";
          sql = String.format(sql, tweetId);
          BaseComment comment;
          commentResultSet = commentStatement.executeQuery(sql);
          while (commentResultSet.next()) {
            // BaseComment(String id, String owner_id, String tweet_id, String content, String
            // created_at)
            comment =
                new BaseComment(
                    commentResultSet.getString(4),
                    commentResultSet.getString(1),
                    tweetId + "",
                    commentResultSet.getString(5),
                    commentResultSet.getTimestamp(6).getTime());
            // UserObject(long id, String name, String headImgUrl, long created_at){
            comment.owner =
                new UserObject(
                    commentResultSet.getLong(1),
                    commentResultSet.getString(2),
                    commentResultSet.getString(3),
                    commentResultSet.getLong(7));
            maopao.comment_list.add(comment);
          }
        }
        maopaos.add(maopao);
      }

      maopaoList.setCode(0);
      maopaoList.setData(maopaos);
    } catch (SQLException e) {
      e.printStackTrace();
      maopaoList.setCode(-1);
      maopaoList.setData(null);
    } finally {
      try {
        if (maopaoResultSet != null) {
          maopaoResultSet.close();
        }
        if (commentResultSet != null) {
          commentResultSet.close();
        }

        if (maopaoStatement != null) {
          maopaoStatement.close();
        }
        if (commentStatement != null) {
          commentStatement.close();
        }

        if (likeUsersResultSet != null) {
          likeUsersResultSet.close();
        }
        if (likeUserStatement != null) {
          likeUserStatement.close();
        }

        if (connection != null) {
          connection.close();
        }

      } catch (SQLException e) {

      }
    }

    return ok(Json.toJson(maopaoList));
  }