benschwarz (owner)

Revisions

gist: 139275 Download_button fork
public
Public Clone URL: git://gist.github.com/139275.git
ffffound.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Download images from ffffound and add to random desktop images.
# Install:
# Add to cron
# Create "FFFFound" directory in ~/Pictures/
# Happiness ensues
 
 
#!/usr/bin/env ruby
require 'rubygems'
require 'nokogiri'
require 'open-uri'
require 'fileutils'
 
module FFFFound
  class << self
    def find
      dispatch!
      doc = Nokogiri::HTML(@response)
      doc.css("img[@id*='asset']").map do |img|
        img.attributes['src']
      end
    end
  
  
    private
    def dispatch!
      @response = open('http://ffffound.com')
    end
  end
end
 
FFFFound.find.each do |img|
  path = "/Users/#{`whoami`.strip!}/Pictures/FFFFound/"
  save_path = path + File.basename(img)
  
  unless File.exists? save_path
    puts "Downloading #{img}"
    File.open(save_path, 'w') {|f| f.write(open(img).read) }
  end
end