Xu Xiaodong avatar Xu Xiaodong committed 36172b3

add fetch_images

Comments (0)

Files changed (3)

 # author:    Xu Xiaodong <xxdlhy@gmail.com>
 # license:   GPL
 # created:   2011 May 03
-# modified:  2011 May 04
+# modified:  2011 May 05
 #
 
 if ARGV.empty?
   puts 'Usage: epub2mobi <file1.epub> [file2.epub] ... [filen.epub]'
 else
-  ARGV.each do |f|
-    system('kindlegen', f)
-  end
+  ARGV.each { |f| system('kindlegen', f) }
 end
 
 # vim: ai:et:ts=2:sw=2:tw=78:ft=ruby
+#!/usr/bin/env ruby
+#
+# name:      fetch_images
+# author:    Xu Xiaodong <xxdlhy@gmail.com>
+# license:   GPL
+# created:   2011 May 06
+# modified:  2011 May 06
+#
+
+require 'nokogiri'
+require 'open-uri'
+
+def fetch_images(url, suffix)
+  doc = Nokogiri::HTML(open(url))
+  doc.xpath('//img').each do |img|
+    img_src = img['src']
+    if img_src.to_s.match("\.#{suffix}$")
+      puts "fetching #{img_src}"
+      system('wget', img_src)
+    end
+  end
+end
+
+if __FILE__ == $0
+  begin
+    fetch_images(*ARGV)
+  rescue ArgumentError => err
+    puts "#{err}, usage: fetch_images <url> <suffix>"
+  end
+end
+
+# vim: ai:et:ts=2:sw=2:tw=78:ft=ruby
 # author:    Xu Xiaodong <xxdlhy@gmail.com>
 # license:   GPL
 # created:   2011 Apr 18
-# modified:  2011 Apr 28
+# modified:  2011 May 06
 #
 
 use Modern::Perl;
 use Getopt::Long;
 
-my $base  = 'http://padevices.com/i/2011/04';
+#my $base  = 'http://padevices.com/i/2011/05';
+my $base  = 'http://linuxtoy.org/img/2011/05';
 my $class = '';
 my $mkd   = 0;
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.