Skip to content

Instantly share code, notes, and snippets.

@joshuaswilcox
Last active December 26, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshuaswilcox/7216225 to your computer and use it in GitHub Desktop.
Save joshuaswilcox/7216225 to your computer and use it in GitHub Desktop.
Get latest Calvin and Hobbes comic and save to folder
#!/usr/bin/env ruby
require 'nokogiri'
require 'net/http'
require 'open-uri'
require 'cgi'
require "fileutils"
# folder where to save the comic to
$basedir = '~/Documents/geeklets/ch_comic'
def get_comic
response = Nokogiri::HTML(open("http://www.gocomics.com/calvinandhobbes"))
comic_img = response.css('div#content div.feature p.feature_item a img')[0]['src']
File.open('/Users/josh/Documents/geeklets/ch_comic/comic.gif', "wb") do |file|
file.write open("#{comic_img}").read
end
end
get_comic
/Users/#{YOUR_USERNAME}/.rvm/rubies/#{YOUR_RUBY_VERSION} > /dev/null
/Users/#{YOUR_USERNAME}/.rvm/rubies/#{YOUR_RUBY_VERSION}/bin/ruby ~/Documents/geeklets/geek_ch.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment