Mercurial > hgrepos > hgweb.cgi > skipweb
view minato2014/admin/chusen.rb @ 577:15acb069930b
Updated
author | MURAKAMI Masaki <c112124@h.koeki-u.ac.jp> |
---|---|
date | Fri, 25 Jul 2014 15:00:12 +0900 |
parents | 79cbef12b16a |
children | 2e0448324d8b |
line wrap: on
line source
#!/usr/bin/env ruby # -*- coding: utf-8 -*- require 'sqlite3' require 'cgi' require 'date' c = CGI.new(:tag_maker => "html5", :accept_charest => "UTF-8") db = SQLite3::Database.new("../sql/stamp.sq3") add = ENV["REMOTE_ADDR"] #hoge = add.split(/(\d+).(\d+).(\d+).(\d+)/) #if add == "172.19.5" || add == "172.17.54" || add == /^172.21.90.\. || add == "1#18.21.142.107" if /^(172\.19\.5\.|172\.17\.54\.|172\.21\.90\.)|118.21.142.107/ =~ add check = c['check'] printf("Content-type: text/html; charset=UTF-8\n\n") sum = 'SELECT SUM(rank) FROM main WHERE NOT id=1;' rank_sum = db.execute(sum).flatten(2)[0].to_i t = Time.now nt = t.hour*60 + t.min p nt p rank_sum if nt > 840 && rank_sum == 0 elsif nt > 880 && rank_sum == 7 else check = "" puts check end if check == "OK" begin result = db.execute("select id,exp,rank from main;") rescue exit end all = Array.new for id,lv,rank in result if id == 1 || lv == 0 || rank.to_i != 0 next end lv.to_i.times do all << id end end tousen = Array.new(0) atari1 = rand(all.length) tousen << all[atari1] all.delete_if {|x| x == tousen[0]} sql = "update main set rank = 1 where id = ?;" db.execute(sql,tousen[0]) sql = "update main set rank = 2 where id = ?;" while tousen.length < 4 srand atari2 = rand(all.length) hoge = all[atari2] tousen << all[atari2] all.delete_if {|x| x == hoge} db.execute(sql,hoge) end i=0 printf("<p>1等はIDが%04dの方!おめでとー!</p>\n",tousen[i].to_i-1) printf("<p>2等はIDが%04dと%04dと%04dの方!おめでとー!</p>\n",tousen[i+=1].to_i-1,tousen[i+=1].to_i-1,tousen[i+=1].to_i-1) else print"<p>抽選はまだ行いませんよ</p>\n" end else printf("Content-type: text/html; charset=UTF-8\n\n") printf'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/h tml4/strict.dtd"> <html> <head> <title>Delete table</title> <link rel="stylesheet" type="text/css" href="design.css"> </head> </body> <p>管理者用ページのため閲覧できません。</p>' end print'</body></html>'