bin/getimage in imagut-0.0.3 vs bin/getimage in imagut-0.0.4

- old
+ new

@@ -1,7 +1,8 @@ #! /usr/bin/env ruby # coding: utf-8 +#! /usr/bin/ruby1.9.3 STORAGE_DIR = ENV["HOME"] + "/inbox/image" LOG_DIR = STORAGE_DIR + "/log" require "pp" @@ -11,25 +12,20 @@ gem "nokogiri" require "nokogiri" require "open-uri" gem "imagut" -require "imagut/urllogger.rb" +require "imagut" +#require "imagut/urllogger.rb" def anchored_images(url) doc = Nokogiri::HTML(open(url)) - #pp doc - #pp doc.methods.sort - #pp doc.children - #pp doc.xpath("//a").each { |i| pp i } - #pp doc.xpath("//a")[10] - #pp doc.xpath("//a")[10].attributes["href"].value results = doc.xpath("//a").map{|a| next unless a.attributes.has_key?("href") a.attributes["href"].value - }.compact.select{|str| str =~ /(jpg|png|gif)$/} + }.compact.select{|str| str =~ /(jpg|jpeg|png|gif)$/} results end #常に log に追記する。 # log に url が含まれていても、 @@ -45,10 +41,10 @@ system command end #anchors = anchored_images('/home/ippei/tmp/getimages/1457652.html') #doc = Nokogiri::HTML(open('http://blog.livedoor.jp/wakusoku/archives/1457652.html')) -ul = UrlLogger.new(LOG_DIR) +ul = Imagut::UrlLogger.new(LOG_DIR) ARGV.each do |url| if ul.include?(url) puts "Already downloaded: #{url}" else