<commit_before>##  Via 
# How to run:
#   ruby alexaby.rb
#
# Output:
#   20 files each with the data in csv format
#
# Credits:   
#   zerothabhishek and glamrock on github
#   
#License: 
#	BSD 2-clause 2012, 2013: zerothabhishek and <NAME>
#   
# Dependencies:
#   ruby version > 1.9  # "ruby -v" to check
#   nokogiri gem        # "gem install nokogiri" to install
##


require 'nokogiri'
require 'open-uri'
require 'csv'
 
def bar(li)
  begin
    site_link=li.css("div.desc-container h2 a")[0].content
    [site_link]
  rescue
    []
  end
end
 
def foo1(url)
  doc = Nokogiri::HTML(open(url))
  listings=doc.css(".site-listing")
  output = listings.collect{|li| bar(li) }
end
 
def foo2(data, i)
  CSV.open("alexaBY.csv","ab") do |csv|
    data.each{|o| csv << o}
  end
end
 
urls = (1..20).to_a.map{|i| "http://www.alexa.com/topsites/countries;#{i}/BY "}
urls.each_with_index do |url,i|
  data=foo1(url)
  foo2(data,i)
end<commit_msg>updated alexaBY.rb to new alexa format<commit_after>##  Via 
# How to run:
#   ruby alexaru.rb
#
# Output:
#   20 files each with the data in csv format
#
# Credits:   
#   zerothabhishek and glamrock on github
#   
#License: 
#	BSD 2-clause 2012, 2013: zerothabhishek and <NAME>
#   
# Dependencies:
#   ruby version > 1.9  # "ruby -v" to check
#   nokogiri gem        # "gem install nokogiri" to install
##


require 'nokogiri'
require 'open-uri'
require 'csv'
 
def bar(li)
  begin
    site_link=li.css("p.desc-paragraph a")[0].content
    [site_link]
  rescue
    []
  end
end
 
def foo1(url)
  doc = Nokogiri::HTML(open(url))
  listings=doc.css("li.site-listing")
  output = listings.collect{|li| bar(li) }
end
 
def foo2(data, i)
  CSV.open("alexaBY.csv","ab") do |csv|
    data.each{|o| csv << o}
  end
end
 
urls = (0..19).to_a.map{|i| "http://www.alexa.com/topsites/countries;#{i}/BY "}
urls.each_with_index do |url,i|
  data=foo1(url)
  foo2(data,i)
end
{'fraction_non_alphanumeric': 0.15493697478991597, 'fraction_numerical': 0.022584033613445378, 'mean_word_length': 3.2905405405405403, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '6766169', 'n_tokens_mistral': 867, 'n_tokens_neox': 804, 'n_words': 185}