Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 8th, 2012  |  syntax: None  |  size: 1.11 KB  |  hits: 12  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # coding: UTF-8
  2.  
  3. # 利用には以下のものが必要です。
  4. # Ruby --- http://www.ruby-lang.org/
  5. # Wget --- http://gnuwin32.sourceforge.net/packages/wget.htm
  6. # Sigil -- http://code.google.com/p/sigil/
  7. #
  8. # 使い方 (https://gist.github.com/1027498 を起点とする例)
  9. # ruby appendix_tree.rb https://gist.github.com/1027498
  10.  
  11. require 'net/https'
  12. require 'uri'
  13. require 'rubygems'
  14. require 'nokogiri'
  15.  
  16. $wget_list = []
  17.  
  18. def gist_get(uri)
  19.   http = Net::HTTP.new(uri.host, uri.port)
  20.   http.use_ssl = true if uri.scheme == "https"  # enable SSL/TLS
  21.   http.start {
  22.     http.request_get(uri.path) {|res|
  23.       temp = Nokogiri::HTML(res.body)
  24.       temp.css("div#files.instapaper_body div.highlight pre div.line").each{|l|
  25.         if (/https:\/\/gist\.github\.com/ =~ l) then
  26.           gist_get(URI.parse(l))
  27.         else
  28.           $wget_list << l.content
  29.         end
  30.       }
  31.     }
  32.   }
  33. end
  34.  
  35.  
  36. start_uri = URI.parse(ARGV[0] || 'https://gist.github.com/1027498')
  37. gist_get(start_uri)
  38.  
  39. File::open("wget_all.bat", "w"){|bat|
  40.   $wget_list.each{|w|
  41.     if (/^wget / =~ w) then
  42.       bat.puts w
  43.     else
  44.       bat.puts "wget -p -nd #{w}"
  45.     end
  46.   }
  47. }