Skip to content

Instantly share code, notes, and snippets.

@mosinski
Created February 16, 2014 08:05
Show Gist options
  • Save mosinski/9030953 to your computer and use it in GitHub Desktop.
Save mosinski/9030953 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# encoding: UTF-8
require 'rubygems'
require 'nokogiri'
require 'open-uri'
unless ARGV[0] and ARGV[1]
puts "Niepoprawne użycie skryptu"
puts "Sposób użycia: script.rb <miesiąc> <dzień>"
puts "Np. ruby script.rb January 25"
exit
end
month = ARGV[0].strip.to_s.capitalize
day = ARGV[1].strip.to_i
if (Date::MONTHNAMES.index(month)==nil)||(day<1)||(day>31)
puts "Podane dane są niepoprawne"
puts "Sposób użycia: script.rb <miesiąc> <dzień>"
puts "Np. ruby script.rb January 25"
exit
end
url = "http://www.namedaycalendar.com/#{month}/#{day}"
begin
@doc = Nokogiri::HTML(open(url))
rescue OpenURI::HTTPError => ex
puts "Brak takiego dnia w kalendarzu.."
exit
end
@countries = @doc.css('div.country').map do |country|
country_name = country.at_css("b").text.strip
names = country.css("div").map(&:content)
puts "-----------------------------"
puts country_name + ": "
if names.length > 3
puts names.first(3).join(", ")
else
puts names.join(", ")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment