Last active
October 3, 2020 08:41
-
-
Save SamirTalwar/f0fd3b23fb98a3ecf197 to your computer and use it in GitHub Desktop.
A really simple command-line Ruby application, for https://monospacedmonologues.com/2016/02/docker-part-three-running-software/.
This file contains 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
FROM ruby | |
RUN mkdir /app | |
WORKDIR /app | |
COPY Gemfile Gemfile | |
RUN bundle install | |
COPY google.rb google.rb | |
RUN chmod +x google.rb | |
ENTRYPOINT ["./google.rb"] | |
CMD ["docker"] |
This file contains 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
source 'https://rubygems.org' | |
gem 'nokogiri' |
This file contains 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 'cgi' | |
require 'nokogiri' | |
require 'open-uri' | |
query = ARGV[0] | |
html = open("https://google.com/search?q=#{CGI.escape(query)}") { |io| | |
Nokogiri::HTML(io) | |
} | |
results = html.css('.g') | |
results.each do |result| | |
header = result.at_css('h3') | |
puts header.text if header | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment