Here's the script, really simple and just a few lines longer than the example on the Stikkit API page (remember to put your API key in there):
#!/usr/local/bin/ruby
require 'net/http'
backup_directory = "/server/homes/alm/stikkits/"
page_number = 1
continue = true
while continue == true
response = Net::HTTP.start('api.stikkit.com') { |http|
req = Net::HTTP::Get.new('/stikkits.txt?api_key=xxxxxxxxxxxxxxxxxxx&page=' + page_number.to_s)
http.request(req)
}
page_number += 1
response.body.split("nf").each do |stikkit|
stikkit_file = File.open(backup_directory + stikkit.split("n")[0].gsub(/W/, '') + ".txt","w+")
stikkit_file << stikkit
stikkit_file.close
end
continue = false if response.body == ""
end
I know that there are probably a million better ways to do this, but I just like having them all backed up as text files. It just works for me.

0 comments:
Post a Comment