Last active
November 26, 2015 16:57
-
-
Save bylatt/783130efb04081caf8e6 to your computer and use it in GitHub Desktop.
Simple ruby script to get wikipedia today's featured article
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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