<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Lucky-Dip Blog: Tag wallpaper</title>
    <link>http://blog.lucky-dip.net/articles/tag/wallpaper</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Random wallpaper from socwall.com</title>
      <description>&lt;p&gt;I quite like http://socwall.com. They have a rss feed for recent posts, but I wrote a small script to download a random selection instead.&lt;/p&gt;
&lt;p&gt;
On OSX I could then set my desktop background to be a random picture from a folder. In my case that folder was /Users/brad/Pictures/Wallpapers/ but that could be easily changed.
&lt;/p&gt;
&lt;p&gt;
The code is after the jump.
&lt;/p&gt;

&lt;pre class="code"&gt;
#!/usr/bin/ruby

require 'rubygems'
require 'hpricot'
require 'open-uri'
require 'Pathname'
 
URL = 'http://socwall.com/browse/index.php?wpSortby=8'
DEST = "/Users/brad/Pictures/Wallpapers/"


def clear_old_images
  Pathname.new(DEST).children.each { |f| f.delete }
end

def download_images(count)
  count = count.to_i
  
  while count &gt; 0
    doc = Hpricot(open(URL))
    
    doc.search("div.wpThumbnail").each do |thumb|
      next if count == 0
      
      thumbnail = thumb.at("img")['src']
      image = thumbnail.gsub(/\/tb_/, '/')
      image = image.gsub(" ", "%20")
      
      remote_image = open(image, "User-Agent" =&gt; "Ruby/#{RUBY_VERSION}")
      local_image = open("#{ DEST }/#{ count }.png", 'w')
      local_image.write(remote_image.read)
      
      remote_image.close
      local_image.close
      
      count -= 1
    end
  end
end

count = ARGV[0] || 10

clear_old_images
download_images(count)

&lt;/pre&gt;</description>
      <pubDate>Mon, 01 Sep 2008 18:10:00 +1000</pubDate>
      <guid isPermaLink="false">urn:uuid:26147d2a-d19b-4164-a22e-ab03958f265c</guid>
      <author>Brad</author>
      <link>http://blog.lucky-dip.net/articles/2008/09/01/random-wallpaper-from-socwall-com</link>
      <category>ruby</category>
      <category>wallpaper</category>
      <trackback:ping>http://blog.lucky-dip.net/articles/trackback/13</trackback:ping>
    </item>
  </channel>
</rss>
