<commit_before>require '/Users/Albert/Repos/Scripts/ruby/lib/utilities.rb'

class BankExperian
    include CommandLineReporter

    def initialize(username, password, security, displays = 'single', headless = false, displayProgress = false)
        @username = username
        @password = password
        @security = security
        @displays = displays
        @headless = headless
        @displayProgress = displayProgress
        @login_uri = 'https://www.creditexpert.co.uk/MCCLogin.aspx'
    end

    # Gets you as far as Experian account overview screen & then returns the browser for (possible) further manipulation.
    def login(browser = getBrowser(@displays, @headless))
        if @displayProgress
            puts "\x1B[90mAttempting to establish connection with: #{@login_uri}\x1B[0m"
        end
        browser.goto(@login_uri)
        browser.text_field(:name => 'loginUser:txtUsername:ECDTextBox', :id => 'loginUser_txtUsername_ECDTextBox').set @username
        browser.text_field(:name => 'loginUser:txtPassword:ECDTextBox', :id => 'loginUser_txtPassword_ECDTextBox').set @password
        browser.input(:type => 'image', :name => 'loginUser:ibtnEnter', :id => 'loginUser_ibtnEnter').click
        if @displayProgress
            puts "\x1B[90mSuccessfully bypassed first page\x1B[0m"
        end
        browser.text_field(:name => 'loginUserMemorableWord:SecurityQuestionUK1_SecurityAnswer1_ECDTextBox').set getCharAt(browser.span(:id => 'loginUserMemorableWord_SecurityQuestionLetter1').text.gsub(/[^0-9]/, ''), @security)
        browser.text_field(:name => 'loginUserMemorableWord:SecurityQuestionUK1_SecurityAnswer2_ECDTextBox').set getCharAt(browser.span(:id => 'loginUserMemorableWord_SecurityQuestionLetter2').text.gsub(/[^0-9]/, ''), @security)
        browser.input(:type => 'image', :name => 'loginUserMemorableWord:ibtnEnter', :id => 'loginUserMemorableWord_ibtnEnter').click
        if @displayProgress
            puts "\x1B[90mSuccessfully logged in to Experian\x1B[0m\n"
        end
        browser
    end

    def getCreditInfo(showInTerminal = false, browser = self.login)
        data = {}
        if browser.span(:id => 'MCC_ScoreIntelligence_ScoreIntelligence_Dial1_MyScoreV31_pnlMyScore1_lblMyScore').exists?
            data['credit_score'] = browser.span(:id => 'MCC_ScoreIntelligence_ScoreIntelligence_Dial1_MyScoreV31_pnlMyScore1_lblMyScore').text
        elsif browser.span(:id => 'MCC_ScoreIntelligence_ScoreIntelligence_Dial1_idScoreAttribBox1_MyScoreV31_pnlMyScore1_lblMyScore').exists?
            data['credit_score'] = browser.span(:id => 'MCC_ScoreIntelligence_ScoreIntelligence_Dial1_idScoreAttribBox1_MyScoreV31_pnlMyScore1_lblMyScore').text
        else
            data['credit_score'] = 'ERROR'
        end
        if showInTerminal
            puts "\n[ #{Rainbow('Experian').foreground('#ff008a')} ]"<commit_msg>Fixed Experian login script (after site was updated).<commit_after>require '/Users/Albert/Repos/Scripts/ruby/lib/utilities.rb'

class BankExperian
    include CommandLineReporter

    def initialize(username, password, security, displays = 'single', headless = false, displayProgress = false)
        @username = username
        @password = password
        @security = security
        @displays = displays
        @headless = headless
        @displayProgress = displayProgress
        @login_uri = 'https://www.creditexpert.co.uk/MCCLogin.aspx'
    end

    # Gets you as far as Experian account overview screen & then returns the browser for (possible) further manipulation.
    def login(browser = getBrowser(@displays, @headless))
        if @displayProgress
            puts "\x1B[90mAttempting to establish connection with: #{@login_uri}\x1B[0m"
        end
        browser.goto(@login_uri)
        browser.text_field(:name => 'Username', :id => 'Username').set @username
        browser.text_field(:name => 'Password', :id => 'Password').set @password
        browser.input(:type => 'button', :id => 'ensSubmitButton').click
        if @displayProgress
            puts "\x1B[90mSuccessfully bypassed first page\x1B[0m"
        end
        browser.text_field(:name => 'Character1').set getCharAt(browser.div(:class => 'form-label', :index => 0).when_present(15).text.gsub(/[^0-9]/, ''), @security)
        browser.text_field(:name => 'Character2').set getCharAt(browser.div(:class => 'form-label', :index => 1).when_present(15).text.gsub(/[^0-9]/, ''), @security)
        browser.input(:type => 'button', :id => 'ensSubmitButton').click
        if @displayProgress
            puts "\x1B[90mSuccessfully logged in to Experian\x1B[0m\n"
        end
        browser
    end

    def getCreditInfo(showInTerminal = false, browser = self.login)
        data = {}
        if browser.span(:id => 'MCC_ScoreIntelligence_ScoreIntelligence_Dial1_MyScoreV31_pnlMyScore1_lblMyScore').exists?
            data['credit_score'] = browser.span(:id => 'MCC_ScoreIntelligence_ScoreIntelligence_Dial1_MyScoreV31_pnlMyScore1_lblMyScore').text
        elsif browser.span(:id => 'MCC_ScoreIntelligence_ScoreIntelligence_Dial1_idScoreAttribBox1_MyScoreV31_pnlMyScore1_lblMyScore').exists?
            data['credit_score'] = browser.span(:id => 'MCC_ScoreIntelligence_ScoreIntelligence_Dial1_idScoreAttribBox1_MyScoreV31_pnlMyScore1_lblMyScore').text
        else
            data['credit_score'] = 'ERROR'
        end
        if showInTerminal
            puts "\n[ #{Rainbow('Experian').foreground('#ff008a')} ]"
{'fraction_non_alphanumeric': 0.11843065693430657, 'fraction_numerical': 0.017153284671532848, 'mean_word_length': 3.7372515125324113, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 39, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4797440', 'n_tokens_mistral': 1697, 'n_tokens_neox': 1648, 'n_words': 289}