Skip to content

Instantly share code, notes, and snippets.

@bylatt
Last active November 26, 2015 16:57
Show Gist options
  • Select an option

  • Save bylatt/783130efb04081caf8e6 to your computer and use it in GitHub Desktop.

Select an option

Save bylatt/783130efb04081caf8e6 to your computer and use it in GitHub Desktop.
Simple ruby script to get wikipedia today's featured article
#!/usr/bin/env ruby
require "nokogiri"
require "open-uri"
wiki_url = "https://en.wikipedia.org/wiki/Main_Page"
doc = Nokogiri::HTML(open(wiki_url))
article = doc.at_css("div#mp-tfa i:first-child a")
title = article.text
url = URI.join(wiki_url, article.attribute('href'))
case ARGV.first
when "what"
puts "Today's featured article is: #{title}"
when "open"
system("open #{url}")
else
puts "Illigal command: #{ARGV.first}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment