Skip to content

Instantly share code, notes, and snippets.

@bmaland
Created September 21, 2008 22:36
Show Gist options
  • Save bmaland/11916 to your computer and use it in GitHub Desktop.
Save bmaland/11916 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
#This code gets all the comic strips from the webcomic
#Saturday Morning Breakfast Cereal (SMBC) and downloads them to a local folder
#Tobias Rusås Olsen (& Bjørn Arild Mæland) - © 2008.
require 'rubygems'
require 'net/http'
require 'active_support'
STARTDATE = "2008-08-31"
TARGETDIR = "bilder/"
Dir.mkdir(TARGETDIR) unless File.exists?(TARGETDIR)
#Lets make some dates
(Date.parse(STARTDATE) .. Date.today).each do |date|
#Lets create the url to catch the picture
Net::HTTP.start("www.smbc-comics.com") do |http|
resp = http.get("/comics/" + date.strftime("%Y%m%d") + ".gif")
next if resp.code == "404" # No comic for this day, file not found
#Lets create local name for picture
this = date.strftime("%Y%m%d") + ".gif"
#Create file and write result.
open(TARGETDIR + this, "wb") do |file|
file.write(resp.body)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment