<commit_before>require 'mechanize'
require 'logger'

module BankScrap
  class Bank

    WEB_USER_AGENT = 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'
    attr_accessor :headers, :accounts

    def initialize(user, password, log: false, debug: false, extra_args: nil)
      @accounts = fetch_accounts
    end

    # Interface method placeholders

    def fetch_accounts
      raise Exception.new "#{self.class} should implement a fetch_account method"
    end

    def fetch_transactions_for(account, start_date: Date.today - 2.years, end_date: Date.today)
      raise Exception.new "#{self.class} should implement a fetch_transactions method"
    end

    private

    def get(url, params = {})
      @http.get(url, params).body
    end

    def post(url, fields)
      @http.post(url, fields, @headers).body
    end

    def put(url, fields)
      @http.put(url, fields, @headers).body
    end

    # Sets temporary HTTP headers, execute a code block
    # and resets the headers
    def with_headers(tmp_headers)
      current_headers = @headers
      set_headers(tmp_headers)
      yield
    ensure
      set_headers(current_headers)
    end


    def set_headers(headers)
      @headers.merge! headers
      @http.request_headers = @headers
    end


    def initialize_cookie(url)
      log 'Initialize cookie'

      @http.url = url
      @http.get(url).body
    end

    def initialize_connection
      @http = Mechanize.new do |mechanize|
        mechanize.user_agent = WEB_USER_AGENT
        mechanize.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        mechanize.log = Logger.new(STDOUT) if @debug
        mechanize.set_proxy 'localhost', 8888
      end

      @headers = {}
    end

    def log(msg)
      puts msg if @log
    end
  end<commit_msg>Ops, let's remove the proxy again<commit_after>require 'mechanize'
require 'logger'

module BankScrap
  class Bank

    WEB_USER_AGENT = 'Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 4 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'
    attr_accessor :headers, :accounts

    def initialize(user, password, log: false, debug: false, extra_args: nil)
      @accounts = fetch_accounts
    end

    # Interface method placeholders

    def fetch_accounts
      raise Exception.new "#{self.class} should implement a fetch_account method"
    end

    def fetch_transactions_for(account, start_date: Date.today - 2.years, end_date: Date.today)
      raise Exception.new "#{self.class} should implement a fetch_transactions method"
    end

    private

    def get(url, params = {})
      @http.get(url, params).body
    end

    def post(url, fields)
      @http.post(url, fields, @headers).body
    end

    def put(url, fields)
      @http.put(url, fields, @headers).body
    end

    # Sets temporary HTTP headers, execute a code block
    # and resets the headers
    def with_headers(tmp_headers)
      current_headers = @headers
      set_headers(tmp_headers)
      yield
    ensure
      set_headers(current_headers)
    end


    def set_headers(headers)
      @headers.merge! headers
      @http.request_headers = @headers
    end


    def initialize_cookie(url)
      log 'Initialize cookie'

      @http.url = url
      @http.get(url).body
    end

    def initialize_connection
      @http = Mechanize.new do |mechanize|
        mechanize.user_agent = WEB_USER_AGENT
        mechanize.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
        mechanize.log = Logger.new(STDOUT) if @debug
      end

      @headers = {}
    end

    def log(msg)
      puts msg if @log
    end
  end
{'fraction_non_alphanumeric': 0.09056603773584905, 'fraction_numerical': 0.016711590296495958, 'mean_word_length': 2.756072874493927, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1421972', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1171, 'n_words': 311}