<commit_before>
require 'watir-webdriver'
require "watir-webdriver/wait"

module AmazonEchoJS
  class Echo
    
    ECHO_URL = 'http://echo.amazon.com/spa/index.html#settings/dialogs'
    REFRESH_TIME_IN_MINUTES = 32
    
    attr_accessor :browser, :last_command, :running, :username, :password, :callback_url
  
    def initialize(username, password, callback_url)
      @callback_url = callback_url
      @username = username
      @password = password
      @last_command = ""
      @running = true #allows us to enter first keep_alive loop
      #keep_alive
    end
    
    def kill
      if @running
        (@browser.close rescue nil) if @browser
        @running = false
        @browser = nil
      end
    end
    
    def keep_alive
      while @running
        begin
          #kill no need to kill browser, just refresh the page.
          sleep(1)
          open_browser
          start_watcher
          sleep(60*REFRESH_TIME_IN_MINUTES)
        rescue Exception => e
          puts e.message
        ensure
          kill
          puts "Killed browser."
          #@running = false #keep running even if error encountered.
        end
      end
    end
    
    def open_browser<commit_msg>shouldn't use method named kill<commit_after>
require 'watir-webdriver'
require "watir-webdriver/wait"

module AmazonEchoJS
  class Echo
    
    ECHO_URL = 'http://echo.amazon.com/spa/index.html#settings/dialogs'
    REFRESH_TIME_IN_MINUTES = 32
    
    attr_accessor :browser, :last_command, :running, :username, :password, :callback_url
  
    def initialize(username, password, callback_url)
      @callback_url = callback_url
      @username = username
      @password = password
      @last_command = ""
      @running = true #allows us to enter first keep_alive loop
      #keep_alive
    end
    
    def kill_browser
      if @running
        (@browser.close rescue nil) if @browser
        @running = false
        @browser = nil
      end
    end
    
    def keep_alive
      while @running
        begin
          #kill_browser no need to kill browser, just refresh the page.
          sleep(1)
          open_browser
          start_watcher
          sleep(60*REFRESH_TIME_IN_MINUTES)
        rescue Exception => e
          puts e.message
        ensure
          kill_browser
          puts "Killed browser."
          #@running = false #keep running even if error encountered.
        end
      end
    end
    
    def open_browser
{'fraction_non_alphanumeric': 0.06794141578519121, 'fraction_numerical': 0.0040683482506102524, 'mean_word_length': 2.032059186189889, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '2816374', 'n_tokens_mistral': 734, 'n_tokens_neox': 720, 'n_words': 201}