<commit_before><?php
/*-------------------------------------------------------+
| Project 60 - Little BIC extension                      |
| Copyright (C) 2014                                     |
| Author: <NAME>                                  |
+--------------------------------------------------------+
| This program is released as free software under the    |
| Affero GPL license. You can redistribute it and/or     |
| modify it under the terms of this license which you    |
| can read by viewing the included agpl.txt or online    |
| at www.gnu.org/licenses/agpl.html. Removal of this     |
| copyright header is strictly prohibited without        |
| written permission from the original author(s).        |
+--------------------------------------------------------*/

require_once 'CRM/Bic/Parser/Parser.php';
require_once 'dependencies/PHPExcel.php';

/**
 * Abstract class defining the basis for national bank info parsers
 */
class CRM_Bic_Parser_ES extends CRM_Bic_Parser_Parser {

  static $page_url = 'http://www.bde.es/f/webbde/IFI/servicio/regis/ficheros/es/REGBANESP_CONESTAB_A.XLS';
  static $country_code = 'ES';

  public function update() {
    // First, download the file
    $file_name = sys_get_temp_dir() . '/es-banks.xls';
    $downloaded_file = $this->downloadFile(CRM_Bic_Parser_ES::$page_url);
    file_put_contents($file_name, $downloaded_file);
    unset($downloaded_file);

    // Automatically detect the correct reader to load for this file type
    $excel_reader = PHPExcel_IOFactory::createReaderForFile($file_name);

    // Set reader options
    $excel_reader->setReadDataOnly();
    $excel_reader->setLoadSheetsOnly(array("ENTIDADES"));

    // Read Excel file
    $excel_object = $excel_reader->load($file_name);
    $excel_rows = $excel_object->getActiveSheet()->toArray();

    // Process Excel data
    $is_header = true;
    $banks[] = array();
    foreach($excel_rows as $excel_row) {
      if($is_header) {
        // Get column Ids from first row
        $column_ids = array();
        foreach($excel_row as $id => $column_name) {
          $column_ids[$column_name] = $id;
        }

        $is_header = false;
      } else {
        // Process every row
        $banks[] = array(
          'value' => CRM_Bic_Parser_ES::$country_code . $excel_row[$column_ids["COD_BE"]],
          'name' => $excel_row[$column_ids["BIC"]],
          'label' => $excel_row[$column_ids["NOMBRE105"]],
          'description' => 'CIF: ' . $excel_row[$column_ids["CODIGOCIF"]],
        );
      }
    }
    unset($excel_rows);
    unset($excel_object);
    unset($excel_reader);

    // Finally, update DB
    return $this->updateEntries(CRM_Bic_Parser_ES::$country_code, $banks);
  }
}<commit_msg>Remove File After Processing It<commit_after><?php
/*-------------------------------------------------------+
| Project 60 - Little BIC extension                      |
| Copyright (C) 2014                                     |
| Author: <NAME>                                  |
+--------------------------------------------------------+
| This program is released as free software under the    |
| Affero GPL license. You can redistribute it and/or     |
| modify it under the terms of this license which you    |
| can read by viewing the included agpl.txt or online    |
| at www.gnu.org/licenses/agpl.html. Removal of this     |
| copyright header is strictly prohibited without        |
| written permission from the original author(s).        |
+--------------------------------------------------------*/

require_once 'CRM/Bic/Parser/Parser.php';
require_once 'dependencies/PHPExcel.php';

/**
 * Abstract class defining the basis for national bank info parsers
 */
class CRM_Bic_Parser_ES extends CRM_Bic_Parser_Parser {

  static $page_url = 'http://www.bde.es/f/webbde/IFI/servicio/regis/ficheros/es/REGBANESP_CONESTAB_A.XLS';
  static $country_code = 'ES';

  public function update() {
    // First, download the file
    $file_name = sys_get_temp_dir() . '/es-banks.xls';
    $downloaded_file = $this->downloadFile(CRM_Bic_Parser_ES::$page_url);
    file_put_contents($file_name, $downloaded_file);
    unset($downloaded_file);

    // Automatically detect the correct reader to load for this file type
    $excel_reader = PHPExcel_IOFactory::createReaderForFile($file_name);

    // Set reader options
    $excel_reader->setReadDataOnly();
    $excel_reader->setLoadSheetsOnly(array("ENTIDADES"));

    // Read Excel file
    $excel_object = $excel_reader->load($file_name);
    $excel_rows = $excel_object->getActiveSheet()->toArray();

    // Process Excel data
    $is_header = true;
    $banks[] = array();
    foreach($excel_rows as $excel_row) {
      if($is_header) {
        // Get column Ids from first row
        $column_ids = array();
        foreach($excel_row as $id => $column_name) {
          $column_ids[$column_name] = $id;
        }

        $is_header = false;
      } else {
        // Process every row
        $banks[] = array(
          'value'       => $excel_row[$column_ids["COD_BE"]],
          'name'        => $excel_row[$column_ids["BIC"]],
          'label'       => $excel_row[$column_ids["NOMBRE105"]],
          'description' => 'CIF: ' . $excel_row[$column_ids["CODIGOCIF"]],
        );
      }
    }

    // Remove temporary file
    unlink($file_name);

    // Free some memory
    unset($excel_rows);
    unset($excel_object);
    unset($excel_reader);

    // Finally, update DB
    return $this->updateEntries(CRM_Bic_Parser_ES::$country_code, $banks);
  }
}
{'fraction_non_alphanumeric': 0.18021265092809516, 'fraction_numerical': 0.003243827716705713, 'mean_word_length': 2.197004608294931, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2445658', 'n_tokens_mistral': 1720, 'n_tokens_neox': 1663, 'n_words': 370}