Skip to content

Instantly share code, notes, and snippets.

@bmaland
Created September 21, 2008 22:36
Show Gist options
  • Save bmaland/11915 to your computer and use it in GitHub Desktop.
Save bmaland/11915 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 'date'
require 'net/http'
STARTDATE = "2008-08-20"
TARGETDIR = "bilder/"
#Lets make some dates
(Date.parse(STARTDATE) .. Date.today).each { |date|
#Lets create the url to catch the picture
Net::HTTP.start("www.smbc-comics.com") { |http|
resp = http.get("/comics/" + date.strftime("%Y%m%d") + ".gif")
next if resp.body.size == 301 # 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") { |file|
file.write(resp.body)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment