<commit_before>module Crags
  module Searcher
    include Fetch

    def strip_http(url)
      url.gsub(/http\:\/\/(.*)\//,'\1')
    end

    def location_doc
      fetch_doc("http://geo.craigslist.org/iso/us")
    end

    def location_links
      location_doc.search("#list a")
    end

    def locations
      location_links.collect{|link| strip_http(link["href"]) }
    end

    def categories
      doc = fetch_doc("http://sfbay.craigslist.org/")
      links = doc.search("table[@summary=\"for sale\"] a")
      categories = {}
      links.each do |link|
        categories[link.inner_html] = link["href"]
      end
      categories
    end

    def search(keyword, category = 'sss', &block)
      locations.collect do |loc|
        sleep(1 + rand(3))
        search_location(keyword, loc, category, &block)
      end.flatten
    end

    def items(doc)
      doc.search("item").collect do |item|
        hashify(item)
      end
    end

    def hashify(item)
      title = item.at("title").inner_text
      url = strip_http(item["rdf:about"])
      {:title => title, :url => url}
    end

    def search_location(keyword, loc, category = 'sss', &block)
      doc = fetch_doc("http://#{loc}/search/#{category}?query=#{keyword}&format=rss")
      items(doc).collect do |item|
        yield item if block_given?
        item
      end
    end
  end
end<commit_msg>added date to items<commit_after>module Crags
  module Searcher
    include Fetch

    def strip_http(url)
      url.gsub(/http\:\/\/(.*)\//,'\1')
    end

    def location_doc
      fetch_doc("http://geo.craigslist.org/iso/us")
    end

    def location_links
      location_doc.search("#list a")
    end

    def locations
      location_links.collect{|link| strip_http(link["href"]) }
    end

    def categories
      doc = fetch_doc("http://sfbay.craigslist.org/")
      links = doc.search("table[@summary=\"for sale\"] a")
      categories = {}
      links.each do |link|
        categories[link.inner_html] = link["href"]
      end
      categories
    end

    def search(keyword, category = 'sss', &block)
      locations.collect do |loc|
        sleep(1 + rand(3))
        search_location(keyword, loc, category, &block)
      end.flatten
    end

    def items(doc)
      doc.search("item").collect do |item|
        hashify(item)
      end
    end

    def hashify(item)
      title = item.at("title").inner_text
      url = strip_http(item["rdf:about"])
      date = DateTime.parse(item.at("dc:date").inner_text)
      {:title => title, :url => url, :date => date}
    end

    def search_location(keyword, loc, category = 'sss', &block)
      doc = fetch_doc("http://#{loc}/search/#{category}?query=#{keyword}&format=rss")
      items(doc).collect do |item|
        yield item if block_given?
        item
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.1417910447761194, 'fraction_numerical': 0.0021321961620469083, 'mean_word_length': 2.3793517406962783, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, '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': '1164562', 'n_tokens_mistral': 925, 'n_tokens_neox': 898, 'n_words': 198}