<commit_before>wesabe.provide('fi-scripts.com.americanexpress.login', {
  dispatch: function() {
    tmp.authenticated = page.present(e.logout.link);

    if (!tmp.authenticated) {
      if (page.present(e.login.error.general)) {
        job.fail(401, 'auth.creds.invalid');
      } else if (page.present(e.login.error.blank)) {
        job.fail(401, 'auth.creds.invalid.blank');
      } else if (page.present(e.login.error.locked)) {
        job.fail(403, 'auth.creds.locked');
      } else if (page.present(e.login.user.field)) {
        action.login();
      }
    }
  },

  alertReceived: function() {
    if (message.match(/Please fill in both the "User ID" and "Password" fields/)) {
      job.fail(401, 'auth.creds.invalid.blank');
    }
  },

  actions: {
    login: function() {
      job.update('auth.creds');
      page.fill(e.login.user.field, answers.username);
      page.fill(e.login.pass.field, answers.password);
      page.click(e.login.continueButton);
    },

    logout: function() {
      job.succeed();
      page.click(e.logout.link);
    },
  },

  elements: {
    login: {
      user: {
        field: [
          // home page
          '//form[@name="ssoform"]//input[@name="Userid"][@type="text"]',
          '//input[@name="Userid"][@type="text"]',
          '//form[@name="ssoform"]//input[@type="text"]',
          // login page
          '//form[@name="frmLogin"]//input[@name="UserID"][@type="text"]',
          '//input[@name="UserID"][@type="text"]',
          '//form[@name="frmLogin"]//input[@type="text"]',
        ],
      },

      pass: {
        field: [
          // home page
          '//form[@name="ssoform"]//input[@name="Pword"][@type="password"]',
          '//input[@name="Pword"][@type="password"]',
          '//form[@name="ssoform"]//input[@type="password"]',
          // login page
          '//form[@name="frmLogin"]//input[@name="Password"][@type="password"]',
          '//input[@name="Password"][@type="password"]',
          '//form[@name="frmLogin"]//input[@type="password"]',
        ],
      },

      error: {
        general: [
          '//text()[contains(., "User ID or Password is incorrect")]',
          '//text()[contains(., "you will be locked out if your next login attempt is unsuccessful")]',
        ],

        blank: [
          '//text()[contains(., "You\'ve left a field blank")]',
        ],

        locked: [
          '//text()[contains(., "Your User ID is locked")]',
        ],
      },

      continueButton: [
        // home page
        '//form[@name="ssoform"]//*[contains(@onclick, "validate")]',
        '//form[@name="ssoform"]//*[@name="btn"][@onclick]',
        // login page
        '//input[contains(@onclick, "loginNow")]',
        '//form[@name="frmLogin"]//input[@type="submit" or @type="image"]',
      ],
    },

    logout: {
      link: [
        '//a[contains(@href, "Logoff")]',
        '//a[contains(@href, "Logout")]',
        '//a[contains(string(.), "Log Off")]',
        '//a[contains(string(.), "Log Out")]',
        '//a[contains(string(.), "Logout")]',
        '//a[contains(string(.), "Logoff")]',
      ],
    },
  },
});
<commit_msg>Fix AMEX scraper.<commit_after>wesabe.provide('fi-scripts.com.americanexpress.login', {
  dispatch: function() {
    tmp.authenticated = page.visible(e.logout.link);

    if (!tmp.authenticated) {
      if (page.present(e.login.error.general)) {
        job.fail(401, 'auth.creds.invalid');
      } else if (page.present(e.login.error.blank)) {
        job.fail(401, 'auth.creds.invalid.blank');
      } else if (page.present(e.login.error.locked)) {
        job.fail(403, 'auth.creds.locked');
      } else if (page.present(e.login.user.field)) {
        action.login();
      }
    }
  },

  alertReceived: function() {
    if (message.match(/Please fill in both the "User ID" and "Password" fields/)) {
      job.fail(401, 'auth.creds.invalid.blank');
    }
  },

  actions: {
    login: function() {
      job.update('auth.creds');
      page.fill(e.login.user.field, answers.username);
      page.fill(e.login.pass.field, answers.password);
      page.click(e.login.continueButton);
    },

    logout: function() {
      job.succeed();
      page.click(e.logout.link);
    },
  },

  elements: {
    login: {
      user: {
        field: [
          // home page
          '//form[@name="ssoform"]//input[@name="Userid"][@type="text"]',
          '//form[@name="ssoform"]//input[@name="UserID"][@type="text"]',
          '//input[@name="Userid"][@type="text"]',
          '//form[@name="ssoform"]//input[@type="text"]',
          // login page
          '//form[@name="frmLogin"]//input[@name="UserID"][@type="text"]',
          '//input[@name="UserID"][@type="text"]',
          '//form[@name="frmLogin"]//input[@type="text"]',
        ],
      },

      pass: {
        field: [
          // home page
          '//form[@name="ssoform"]//input[@name="Pword"][@type="password"]',
          '//form[@name="ssoform"]//input[@name="Password"][@type="password"]',
          '//input[@name="Pword"][@type="password"]',
          '//form[@name="ssoform"]//input[@type="password"]',
          // login page
          '//form[@name="frmLogin"]//input[@name="Password"][@type="password"]',
          '//input[@name="Password"][@type="password"]',
          '//form[@name="frmLogin"]//input[@type="password"]',
        ],
      },

      error: {
        general: [
          '//text()[contains(., "User ID or Password is incorrect")]',
          '//text()[contains(., "you will be locked out if your next login attempt is unsuccessful")]',
        ],

        blank: [
          '//text()[contains(., "You\'ve left a field blank")]',
        ],

        locked: [
          '//text()[contains(., "Your User ID is locked")]',
        ],
      },

      continueButton: [
        // home page
        '//form[@name="ssoform"]//*[contains(@onclick, "validate")]',
        '//form[@name="ssoform"]//*[@name="btn"][@onclick]',
        '//form[@name="ssoform"]//input[@type="submit" or @type="image"]',
        // login page
        '//input[contains(@onclick, "loginNow")]',
        '//form[@name="frmLogin"]//input[@type="submit" or @type="image"]',
      ],
    },

    logout: {
      link: [
        '//a[contains(@href, "Logoff")]',
        '//a[contains(@href, "Logout")]',
        '//a[contains(string(.), "Log Off")]',
        '//a[contains(string(.), "Log Out")]',
        '//a[contains(string(.), "Logout")]',
        '//a[contains(string(.), "Logoff")]',
      ],
    },
  },
});

{'fraction_non_alphanumeric': 0.23504208110175975, 'fraction_numerical': 0.003672532517214996, 'mean_word_length': 2.259850374064838, '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': '6616538', 'n_tokens_mistral': 2167, 'n_tokens_neox': 2117, 'n_words': 295}