1: 2003-12-04 (木) 23:09:00 [5] | |||
---|---|---|---|
Line 1: | Line 1: | ||
+ | *OSASK-ML のURLとナンバーへのリンクCGI | ||
+ | MLへのリンクができないとつまんないので、つくってみた。Rubyですにょ。 | ||
+ | |||
+ | *スクリプト | ||
+ | #!/usr/local/bin/ruby | ||
+ | |||
+ | require 'net/http' | ||
+ | require 'cgi' | ||
+ | |||
+ | cgi = CGI.new | ||
+ | par = [] | ||
+ | todaystr = Time.now.strftime("%Y%m%d") | ||
+ | a = true | ||
+ | |||
+ | Dir.glob("\.\/????????.txt").each do |f| | ||
+ | if "./#{todaystr}.txt" == f then | ||
+ | a = false | ||
+ | else | ||
+ | File.delete(f) | ||
+ | end | ||
+ | end | ||
+ | |||
+ | if a then | ||
+ | |||
+ | Net::HTTP.start( 'www.afis.to', 80 ) {|http| | ||
+ | response , = http.get('/~mone/osask/osask_ml/index.html') | ||
+ | response.body.split("\n").each{|pul| | ||
+ | if /HREF=\"(\d{6})\/\"\>/ =~ pul then | ||
+ | par << $1 | ||
+ | end | ||
+ | } | ||
+ | } | ||
+ | |||
+ | open("./#{todaystr}.txt", "w") do |f| | ||
+ | par.each { |pname| | ||
+ | Net::HTTP.start( 'www.afis.to', 80 ) {|http| | ||
+ | response , = http.get("/~mone/osask/osask_ml/#{pname}/index.html") | ||
+ | response.body.split("\n").each{|pul| | ||
+ | if /HREF=\"msg(\d{5})\.html\"\>\[(?:OSASK|osask) (\d+)\] (.+)\<\/A\>/ =~ pul then | ||
+ | surl = "http://www.afis.to/~mone/osask/osask_ml/#{pname}/msg#{$1}.html" | ||
+ | smid = "[OSASK #{$2}]" | ||
+ | smti = "#{$3}" | ||
+ | f << $2 + "\t" + surl + "\n" | ||
+ | end | ||
+ | } | ||
+ | } | ||
+ | } | ||
+ | end | ||
+ | end | ||
+ | |||
+ | returl = "" | ||
+ | inn = cgi['n'].to_s | ||
+ | |||
+ | if inn then | ||
+ | open("./#{todaystr}.txt") do |f| | ||
+ | while f.gets | ||
+ | if /(\d+)\t(.+)$/ =~ $_ then | ||
+ | returl = $2 if $1 == inn | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | end | ||
+ | |||
+ | if returl != "" then | ||
+ | print cgi.header({"Location" => returl }) | ||
+ | print "転送 >> #{returl}" | ||
+ | else | ||
+ | cgi.out{"みつからない~ぐへぇ・・・"} | ||
+ | end | ||
+ | |||
+ | *何に使うんだ? | ||
+ | |||
+ | WikiからML発言ナンバーでリンクしたくて・・・それだけです。・・・最近Rubyネタばっかりだな 笑 |
(This host) = http://osask.net