예제 #1
0
  public List<Map<String, Object>> getTwitter(String url, Context context) {
    ArrayList<Map<String, String>> json = this.JSON(url, context);
    List<Map<String, Object>> tweets = new ArrayList<Map<String, Object>>();
    Map<String, Object> data;
    if (json.get(0).get("internet").equals("true")) {
      for (int i = 0; i < json.size(); i++) {
        try {
          data = new HashMap<String, Object>();
          Log.i("JSON Lista Recebida", i + " -> " + json.get(i).toString());
          Tweet tweet =
              new Tweet(
                  json.get(i).get("texto"),
                  json.get(i).get("autor"),
                  json.get(i).get("imagem"),
                  json.get(i).get("date"));

          data.put("internet", true);
          data.put("text", tweet.getText());
          data.put("author", tweet.getAuthor());
          data.put("image", tweet.getImage());
          data.put("datetime", tweet.getDate());

          tweets.add(data);
        } catch (Exception e) {
          Log.e("JSON - Tweets", e.getMessage() + " " + e.getStackTrace());
        }
      }
    } else {
      data = new HashMap<String, Object>();
      data.put("internet", false);
      tweets.add(data);
    }
    return tweets;
  }
예제 #2
0
  /** @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response) */
  protected void doPost(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
    // TODO Auto-generated method stub
    HttpSession session = request.getSession(true);

    String user = "";
    if (session.getAttribute("tweetics") == null) {
      response.sendRedirect("twitter");
    } else {
      user = session.getAttribute("tweetics").toString();
    }

    TweetAnalytics abs = new TweetAnalytics(request.getParameter("key"));
    String connectionURL = "jdbc:mysql://localhost/tweetics";
    Connection connection = null;

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    try {
      Class.forName("com.mysql.jdbc.Driver").newInstance();
      connection = DriverManager.getConnection(connectionURL, "andre", "susanto");

      Statement statement = connection.createStatement();

      ResultSet algo =
          statement.executeQuery(
              "SELECT algoritma,`count` FROM `user` WHERE `username`='" + user + "'");
      algo.first();
      String pilAlgo = algo.getString(1);
      int count = algo.getInt(2);

      if (pilAlgo.equals("1")) {
        pilAlgo = "KMP";
      } else {
        pilAlgo = "BoyerMoore";
      }

      // out.println(pilAlgo);

      ResultSet cats =
          statement.executeQuery("SELECT * FROM `category` WHERE `username`='" + user + "'");
      boolean n = cats.first();

      while (n) {
        if (!cats.getString(2).equals("Unknown")) {
          abs.AddCategory(cats.getString(2), cats.getString(3));
        }
        // out.println(cats.getString(2)+" "+cats.getString(3));
        n = cats.next();
      }
      // out.println("SU");
      PreparedStatement preparedStatement;
      // preparedStatement = connection.prepareStatement("INSERT INTO `tweets` (`id_tweet`,
      // `username`, `category`, `tweet_content`, `location_name`, `location_pos`, `tweet_user`,
      // `tweet_pic`, `tweet_time`, `keyword_match`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?);");

      List<Category> cat = abs.GetResult(pilAlgo, count);

      for (Category aa : cat) {
        for (Tweet ab : aa.tweets) {
          // out.println("");
          preparedStatement =
              connection.prepareStatement(
                  "INSERT INTO `tweets` (`id_tweet`, `username`, `category`, `tweet_content`, `location_name`, `location_pos`, `tweet_user`, `tweet_pic`, `tweet_time`, `keyword_match`) VALUES (NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?);");

          //		   			out.println(aa.name);
          //		   			out.println( ab.getStatus());
          //		   			out.println( ab.getLocation());
          //		   			out.println( ab.getKor());
          //		   			out.println( ab.getUser());
          //		   			out.println( ab.getImage());
          //		   			out.println( getCurrentTimeStamp());
          //		   			out.println( ab.getKeyword());
          //
          preparedStatement.setString(1, user);
          preparedStatement.setString(2, aa.name);
          preparedStatement.setString(3, ab.getStatus());
          preparedStatement.setString(4, ab.getLocation());
          preparedStatement.setString(5, ab.getKor());
          preparedStatement.setString(6, ab.getUser());
          preparedStatement.setString(7, ab.getImage());
          preparedStatement.setString(8, getCurrentTimeStamp());
          preparedStatement.setString(9, ab.getKeyword());
          preparedStatement.executeUpdate();
        }
      }

    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    response.sendRedirect("analisa.jsp?cat=all");
  }