<commit_before>require 'active_support/concern'

require 'speedrundotcom'

module SRDCRun
  extend ActiveSupport::Concern

  included do
    def srdc_url
      SpeedrunDotCom::Run.url_from_id(srdc_id) if srdc_id.present?
    end

    def srdc_url=(url)
      srdc_id = SpeedrunDotCom::Run.id_from_url(url)
    end

    def set_runner_from_srdc
      return if srdc_id.nil?
      update(user:
        User.find_by(
          name: SpeedrunDotCom.user(
            SpeedrunDotCom.run(srdc_id).players[0]['id']
          ).twitch_login
        )
      )
    rescue SpeedrunDotCom::RunNotFound, SpeedrunDotCom::UserNotFound
    end
  end
end<commit_msg>Guard against speedrun.com failed calls<commit_after>require 'active_support/concern'

require 'speedrundotcom'

module SRDCRun
  extend ActiveSupport::Concern

  included do
    def srdc_url
      SpeedrunDotCom::Run.url_from_id(srdc_id) if srdc_id.present?
    end

    def srdc_url=(url)
      srdc_id = SpeedrunDotCom::Run.id_from_url(url)
    end

    def set_runner_from_srdc
      return if srdc_id.nil? || user.present?

      srdc_run = SpeedrunDotCom.run(srdc_id)
      return if srdc_run.blank?

      srdc_runner = SpeedrunDotCom.user(srdc_run.players[0]['id'])
      return if srdc_runner.blank?

      update(user: User.find_by(srdc_runner.twitch_login))
    rescue SpeedrunDotCom::RunNotFound, SpeedrunDotCom::UserNotFound, SpeedrunDotCom::
    end
  end
end
{'fraction_non_alphanumeric': 0.0850914205344585, 'fraction_numerical': 0.0014064697609001407, 'mean_word_length': 3.3784615384615386, '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': '4715331', 'n_tokens_mistral': 530, 'n_tokens_neox': 524, 'n_words': 87}