<commit_before>require 'cinch'
require 'open-uri'
require 'nokogiri'
require 'cgi'

class Google
  include Cinch::Plugin
  plugin "google"
  help "!g(oogle) [number] <query> - search Google"
  match /g(?:oogle)? (.+)/

  def execute(m, query)
    stop = 4
    query = query.split(/\s+/).join(" ")

    url = "http://www.google.com/search?q=#{CGI.escape(query)}"

    doc = Nokogiri::HTML(open(url))
    results = doc.css('h3.r a.l')[0..(stop)]

    if results[0].nil?
      m.reply "No results found."
    else
      results.each do |result|
        if result.nil?
          m.reply "No more results."
          break
        else
          m.reply "#{result.text} (#{result['href']})"
        end
      end
    end
  end
end

<commit_msg>Tweak regex following dominikh's advice<commit_after>require 'cinch'
require 'open-uri'
require 'nokogiri'
require 'cgi'

class Google
  include Cinch::Plugin
  plugin "google"
  help "!g(oogle) [number] <query> - search Google (5 default results; give number for less)"
  match /g(?:oogle)? (?:(\d+) )?(.+)/

  def execute(m, number, query)
    number ||= 5
    query = query.split(/\s+/).join(" ")

    url = "http://www.google.com/search?q=#{CGI.escape(query)}"

    doc = Nokogiri::HTML(open(url))
    results = doc.css('h3.r a.l')[0..(number.to_i - 1)]

    if results[0].nil?
      m.reply "No results found."
    else
      results.each do |result|
        if result.nil?
          m.reply "No more results."
          break
        else
          m.reply "#{result.text} (#{result['href']})"
        end
      end
    end
  end
end


{'fraction_non_alphanumeric': 0.16962025316455695, 'fraction_numerical': 0.006329113924050633, 'mean_word_length': 2.414686825053996, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, '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': '279055', 'n_tokens_mistral': 577, 'n_tokens_neox': 557, 'n_words': 138}