OSDN Git Service

refactored
[tdcgexplorer/nimono-crawlers.git] / bin / mmdfile-idx.rb
1 #!/usr/bin/ruby
2 # download from mikumikudance
3 # http://loda.jp/mmdfile/
4
5 $LOAD_PATH.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
6 require 'sn_uploader'
7
8 def each_id(text)
9   file_href = '?id='
10   file_re = Regexp.new(Regexp.escape(file_href) + '(\d+)\\z')
11   text.scan(/href="(.+?)"/) do |href, |
12     if md = file_re.match(href)
13       yield md[1]
14     end
15   end
16 end
17
18 uploader = SnUploader.new
19 uploader.host = "loda.jp"
20 uploader.root_path = "/mmdfile"
21 uploader.local_dir = '/Volumes/uploader/arc/mmdfile'
22   uploader.base_html = "/"
23   body = uploader.get_base
24   open('/Volumes/uploader/src/mmdfile/index.html', 'w'){ |f| f.puts body }
25   each_id(body) do |id|
26     filename = id + '.zip'
27     exist = uploader.local_file_exist?(filename)
28     puts [ id, exist ? 'exist' : 'download' ].join("\t")
29     uploader.download_file_directly_id(filename)
30   end