2chã®å¯¾è±¡ã®æ¿ã«ããã¹ã¬ããå ¨é¨ã®datãåå¾ããã¹ã¯ãªãã
大éã®æç« ãã¡ã¤ã«ã欲ããã£ãã®ã§ã(><)
ã¨ããããã§2chããæç« ã¨ã£ã¦æ¥ããã¨ã¹ã¯ãªãããrubyã§ä½ã£ãã
#!/usr/local/bin/ruby require 'net/http' require 'kconv' $KCODE='u' URLS = ['http://yutori.2ch.net/news4vip/'] def make_dir(dir_path) full_path = Dir.pwd dir_path.split(/\//).each do | path | full_path = File.join(full_path, path ) Dir.mkdir(full_path) unless File.exist?(full_path) return false unless File::ftype(full_path) == "directory" end full_path end def get_subject(url) bbsname = url.split('://').last dir_path = make_dir(bbsname) subject_url = "#{url}subject.txt" Net::HTTP.get(URI.parse(subject_url)).toutf8.each do | body | body_spliter = body.split("<>") body_spliter[1] =~ /(.*)\((\d+)\)\n$/ file_name = File.join(dir_path,"#{body_spliter[0]}.#{$2}.dat") files = Dir.glob("#{dir_path}\/#{body_spliter[0]}*") unless files.include?(file_name) files.each do | file | File.delete(file) end output_file = File.open(file_name,'w') output_file.puts Net::HTTP.get(URI.parse("#{url}dat/#{body_spliter[0]}")) output_file.close p "#{file_name}/#{$1} get" sleep 5 end end end URLS.each do | url | get_subject(url) end
sleep 5ã¯æå¾ã®è¯å¿ã