Пример #1
0
  public static void main(String[] args) {
    if (args.length == 0) {
      System.out.println("You must specify the idRun you want to relaunch");
    }
    try {
      String idRun = args[0];
      DataBaseManagement.instantiante_connection();
      DataBaseManagement.reopen(idRun);
      String idCheck = DataBaseManagement.get_check_id(idRun);
      // getting the target associated with the group
      //			ResultSet target_resultSet = DataBaseManagement.search_target(idGroup);
      //			while (target_resultSet.next()) {
      //			target=target_resultSet.getString("name");
      //			idTarget=target_resultSet.getString("idTarget");
      //			System.out.println("target: " + target);
      //			System.out.println("idTarget: " + idTarget);
      //		}

      String target = "wwww.cdiscount.com";
      String idTarget = "1";
      //
      ResultSet missing_keyword_resultSet = DataBaseManagement.search_missing_keywords(idCheck);
      while (missing_keyword_resultSet.next()) {
        String idKeyword = missing_keyword_resultSet.getString("idKeyword");
        String keyword_name = missing_keyword_resultSet.getString("name");
        // System.out.println("idKeyword: " + idKeyword);
        System.out.println("Launching keyword: " + keyword_name);

        // asynchronous launch
        // GoogleSearchSaveTask beep=new GoogleSearchSaveTask(checkId, idTarget,
        // idKeyword,keyword_name);

        // Synchronous launch but waiting after
        RankInfo loc_info = ranking_keyword(keyword_name, target);
        DataBaseManagement.insertKeyword(
            idCheck, idTarget, idKeyword, loc_info.getPosition(), loc_info.getUrl());
      }

      // closing the run by inserting a stopping date !
      DataBaseManagement.close_current_run();
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      DataBaseManagement.close();
    }
  }
Пример #2
0
 @Override
 public void run() {
   System.out.println(
       "ReminderTask is completed by Java timer :"
           + keyword_to_search
           + idCheck
           + idTarget
           + idKeyword);
   timer.cancel(); // Not necessary because we call System.exit
   // System.exit(0); //Stops the AWT thread (and everything else)
   RankInfo loc_info = ranking_keyword(keyword_to_search);
   try {
     DataBaseManagement.insertKeyword(
         idCheck, idTarget, idKeyword, loc_info.getPosition(), loc_info.getUrl());
   } catch (SQLException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
     System.out.println("Error when database saving " + keyword_to_search);
   }
 }
  public static void main(String[] args) {
    System.setProperty("http.agent", "");
    // we here add just a single  user agent
    user_agents.add(
        "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB;     rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 (.NET CLR 3.5.30729)");

    try {
      DataBaseManagement.instantiante_connection();
      int counter = DataBaseManagement.check_alive_run();
      if (counter >= 1) {
        System.out.println("Cron : Fatal, another job is running");
        return;
      }
      java.sql.Date current_Date = new java.sql.Date(System.currentTimeMillis());
      long generated_run_id = DataBaseManagement.insertRunById(current_Date);
      String runId = Long.toString(generated_run_id);
      System.out.println("Generated run id for the cron job" + runId);

      // getting our groups
      ResultSet group_resultSet = DataBaseManagement.search_group(args);

      // we here loop over each group
      while (group_resultSet.next()) {
        String idGroup = group_resultSet.getString("idGroup");
        String name = group_resultSet.getString("name");
        String module = group_resultSet.getString("module");
        String options = group_resultSet.getString("options");
        System.out.println("idGroup: " + idGroup);
        System.out.println("module: " + module);
        System.out.println("name: " + name);
        System.out.println("options: " + options);
        // Getting the targeted site to SERP
        // for the moment we only target cdiscount !
        ResultSet target_resultSet = DataBaseManagement.search_target(idGroup);
        String target = null;
        String idTarget = null;
        while (target_resultSet.next()) {
          target = target_resultSet.getString("name");
          idTarget = target_resultSet.getString("idTarget");
          System.out.println("target: " + target);
          System.out.println("idTarget: " + idTarget);
        }

        // inserting a check row in the check table
        long idCheck =
            DataBaseManagement.insertCheckById(
                current_Date, idGroup, Long.toString(generated_run_id));
        String checkId = Long.toString(idCheck);
        System.out.println("Generated check id for the cron job" + checkId);
        // select the keywords to update
        ResultSet keyword_resultSet = DataBaseManagement.search_keywords(idGroup);
        while (keyword_resultSet.next()) {
          String idKeyword = keyword_resultSet.getString("idKeyword");
          String keyword_name = keyword_resultSet.getString("name");
          // System.out.println("idKeyword: " + idKeyword);
          System.out.println("Launching keyword: " + keyword_name);

          // asynchronous launch
          // GoogleSearchSaveTask beep=new GoogleSearchSaveTask(checkId, idTarget,
          // idKeyword,keyword_name);

          // Synchronous launch but waiting after
          RankInfo loc_info = proxy_ranking_keyword(keyword_name, target);
          DataBaseManagement.insertKeyword(
              checkId, idTarget, idKeyword, loc_info.getPosition(), loc_info.getUrl());
        }

        // closing the run by inserting a stopping date !
        DataBaseManagement.close_current_run();
      }
    } catch (SQLException e) {
      e.printStackTrace();
    } finally {
      DataBaseManagement.close();
    }
  }