Mercurial > hgrepos > hgweb.cgi > skipweb
changeset 3429:192062680d0b
プログラムの改良
author | houtin <c115080@g.koeki-u.ac.jp> |
---|---|
date | Thu, 27 Jul 2017 16:58:27 +0900 |
parents | ed1a15e1c32d |
children | db8a429871af |
files | event/oasis2017/point.sq3 event/oasis2017/quiz/1-2.png event/oasis2017/quiz/db/point.sq3 event/oasis2017/quiz/gassan.jpg event/oasis2017/quiz/gassan_mini.jpg event/oasis2017/quiz/kantan.rb event/oasis2017/quiz/quiz.csv event/oasis2017/quiz/quiz.rb event/oasis2017/quiz/quizpg.css event/oasis2017/quiz/shishi.jpg event/oasis2017/quiz/shishi_mini.jpg event/oasis2017/quiz/tyokai.jpg |
diffstat | 11 files changed, 238 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/event/oasis2017/quiz/kantan.rb Thu Jul 27 14:41:25 2017 +0900 +++ b/event/oasis2017/quiz/kantan.rb Thu Jul 27 16:58:27 2017 +0900 @@ -30,9 +30,7 @@ # 1501044365/65675|unko|2017-07-26 14:43:14 +0900|qa3 -someVALUES1 = "qa1" -someVALUES2 = "qa2" -someVALUES3 = "qa3" +key = ["qa1","qa2","qa3"] #cookie≫ @@ -68,6 +66,20 @@ # cookie∫c障сc + +print(<<-EOF) +<!DOCTYPE html> +<html lang="ja"> +<head><title>膂≦</title> +<link rel="stylesheet" type="text/css" href="quizpg.css" > +<meta name="viewport" content="width=device-width,initial-scale=1"> +</head> +<body> + +EOF + + + ################################################################## 若句脂 playname = form_name if form_name > "" # 若name @@ -91,7 +103,7 @@ EOF exit end -printf("<h1>%sc潟</h1>\n", playname) +printf("<p class=\"big\">%s<br>c潟</p>\n", playname) ################################################################## @@ -110,16 +122,6 @@ number = "1" #number"1"篁e end -print(<<-EOF) -<!DOCTYPE html> -<html lang="ja"> -<head><title>膂≦</title> -<link rel="stylesheet" type="text/css" href="" > -<meta name="viewport" content="width=device-width,initial-scale=1"> -</head> -<body> - -EOF @@ -141,11 +143,11 @@ "13" => [] } -y = {"1" => "hiyori.png<br>" +y = {"1" => "hiyori.jpg<br>" } -print"<html><head><title>ゃ</title></head><body>\n" +#print"<html><head><title>ゃ</title></head><body>\n" print"<form method=\"POST\" action=\"./kantan.rb\">\n" @@ -174,19 +176,19 @@ printf("<video controls wight=\"320\"height=\"240\"><source src=\"skipseikai1.mp4\"></video>") print("<\p>") printf("<label><input type=\"radio\" name=\"rd\" value=\"5\">罨<檎蚊<br></label>") - db.execute("REPLACE INTO point VALUES(?,?)",id,someVALUES1) + db.execute("REPLACE INTO point VALUES(?,?)",id,key[0]) elsif number =="8" print("<p>") printf("<video controls wight=\"320\"height=\"240\"><source src=\"skipseikai4.mp4\"></video>") print("</p>") printf("<label><input type=\"radio\" name=\"rd\" value=\"9\">罨<檎蚊<br></label>") - db.execute("REPLACE INTO point VALUES(?,?)",id,someVALUES2) + db.execute("REPLACE INTO point VALUES(?,?)",id,key[1]) elsif number == "10" print("<p>") printf("<video controls wight=\"320\"height=\"240\"><source src=\"skipseikai5.mp4\"></video>") print("<\p>") printf("<label><input type=\"radio\" name=\"rd\" value=\"13\">罨<檎蚊<br></label>") - db.execute("REPLACE INTO point VALUES(?,?)",id,someVALUES3) + db.execute("REPLACE INTO point VALUES(?,?)",id,key[2]) end printf("<input type=\"submit\" value=\"罨<\">")
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/event/oasis2017/quiz/quiz.csv Thu Jul 27 16:58:27 2017 +0900 @@ -0,0 +1,10 @@ +#腮,馹,糸<ゃ若劫,御1,御2,御3,罩hВ,祉<ゃ +kantan,1,hiyori,藏翫,ュ絮怨,蕋罍絮怨,2,skipseikai1.mp4 +kantan,2,tyokai,絮,臂初絮,薐ユ儀絮,3,skipseikai4.mp4 +kantan,3,sannkyo,絮怨綺,綺,乗膊,1,skipseikai5.mp4 +futsu,1,tama,膂障羯,膤吾羯,筝羯,1,skipseikai1.mp4 +futsu,2,12,筝羯,篋羯,筝羯,2,skipseikai4.mp4 +futsu,3,shishi,絽綵号紊х絖,育紊х絖,,1,skipseikai5.mp4 +muzukashi,1,gassan,薐ユ儀絮,羚罧水臼,絮,3,skipseikai1.mp4 +muzukashi,2,maru,筝御罕,羆,藏顔羆,1,skipseikai4.mp4 +muzukashi,3,1-2,筝羯篋羯,筝羯,筝羯,1,skipseikai5.mp4
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/event/oasis2017/quiz/quiz.rb Thu Jul 27 16:58:27 2017 +0900 @@ -0,0 +1,199 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- +# +# 罧茯臥 [css茯炊] [篁蚊若若帥若鴻<ゃg鎧] +# 若九≪ http:/..../quiz.rb?reset + +require 'cgi' +require 'csv' +c = CGI.new(:accept_charset => 'utf-8') + +require 'sqlite3' +file = "db/point.sq3" + +# roy{c115080}% sqlite3 point.sq3 [~/public_html/mycgi/skip/quiz/db] +# SQLite version 3.8.8.2 2015-01-30 14:30:45 +# Enter ".help" for usage hints. +# sqlite> .sch +# CREATE TABLE users(id text primary key, name text, creation text); +# CREATE TABLE point(id, keyword text, FOREIGN KEY(id) REFERENCES users(id)); +# sqlite> select * from users; +# 1501044365/65675|unko|2017-07-26 14:43:14 +0900 +# sqlite> select * from point; +# 1501044365/65675|c +# sqlite> select * from users NATURAL INNER JOIN point; +# 1501044365/65675|unko|2017-07-26 14:43:14 +0900|c +# 1501044365/65675|unko|2017-07-26 14:43:14 +0900|c +# 1501044365/65675|unko|2017-07-26 14:43:14 +0900| +# 1501044365/65675|unko|2017-07-26 14:43:14 +0900|qa1 +# 1501044365/65675|unko|2017-07-26 14:43:14 +0900|qa2 +# 1501044365/65675|unko|2017-07-26 14:43:14 +0900|qa3 + +myname = File.basename($0) + +#cookie≫ +cookie_id=c.cookies["id"][0] + +form_name =c["playname"] # ュ +form_mode =c["mode"] # 馹腮 +form_qn =c["qn"] # 馹 +form_rd =c["rd"] # 茹g + +if cookie_id == nil + newid = Time.now.to_i.to_s + "/" + rand(99999).to_s + id = newid +else + id = cookie_id +end + +# idcookieх御吟 +# 紊違24荐絎expire紊違ャ +expire = (Time.now+24*3600).gmtime.strftime("%a, %d %b %Y %H:%M:%S GMT") +printf("Content-type: text/html; charset=UTF-8\n") +printf("Set-Cookie: id=%s; expires=%s\n\n", id, expire) + +db = SQLite3::Database.new(file) +db.execute("PRAGMA foreign_keys=on") +db.execute("CREATE TABLE IF NOT EXISTS " + + "users(id text primary key, name text, creation text)") +db.execute("CREATE TABLE IF NOT EXISTS " + + "point(id, keyword text, FOREIGN KEY(id) REFERENCES users(id), " + + "UNIQUE(id,keyword))") + +################################################################## 若句脂 +playname = form_name +if form_name > "" # 若name + now = Time.now.strftime("%F %T") + db.execute("REPLACE INTO users VALUES(?, ?, ?)", id, form_name, now); +else # 若namedb + dbn = db.execute("SELECT name from users WHERE id=?", id)[0] + if dbn != nil && dbn[0] + playname = dbn[0] # 若帥若鴻ゅ + end +end +if playname == "" || ARGV[0] == "reset" + print(<<-EOF) + <form action="#{myname}" method="POST"> + <p>ゅャ: + <input type="text" name="playname"> + <input type="submit" value="篆"> + <input type="reset" value="祉"> + </form> + EOF + exit +end +printf("<h1>%sc潟</h1>\n", playname) +################################################################## + +number = c["rd"] +def outinput(value, label) + printf("<label><input type=\"radio\" name=\"rd\" value=\"%s\">%s</label>", value, label) +end + +def imgsrc(img) + printf("<a href=\"%s.jpg\"\><img src=\"%s_mini.jpg\"></a>", img, img) +end + +## 馹宴茯粋昭 +question = {} +n_question = 0 +CSV.foreach("quiz.csv", encoding: 'utf-8') do |row| + mode = row.shift # = ≪若 + next if /^#/ =~ mode # 荀冴茵鴻 + if question[mode] == nil + question[mode] = {} + end + qn = row.shift # 馹 + question[mode][qn] = row # {1 => [tama, 膂, ....]} + n_question += 1 # т +end + +puts("<!DOCTYPE html>\n<html lang=\"ja\">") + +if form_mode > "" + quiz_mode = form_mode +else + quiz_mode = ARGV[0] || "futsu" # kantan, futsu, muzukashi +end +if not /kantan|futsu|muzukashi/ =~ quiz_mode then + print(<<-EOF) + <head><title>ERROR</title></head><body> + <h1>≦鴻潟若с</h1></body></html> + EOF + exit 0 +end + +level = {"kantan" => "膂≦", "futsu"=>"", "muzukashi"=>"c"}[quiz_mode] + +print(<<-EOF) +<!DOCTYPE html> +<html lang="ja"> +<head><title>#{level}</title> +<link rel="stylesheet" type="text/css" href="quizpg.css" > +<meta name="viewport" content="width=device-width,initial-scale=1"> +</head> +<body> + +EOF + +print"<html><head><title>ゃ</title></head><body>\n" + +print"<form method=\"POST\" action=\"./#{myname}\">\n" + +q = question[quiz_mode] # 3腮< + +if form_qn == nil || form_qn == "" # 馹垽絎1 + form_qn = "1" +end +ansinfo = q[form_qn] # 篁御≪茹g +# [hiyori,藏翫,ュ絮怨,蕋罍絮怨,2,skipseikai1.mp4] 絖 +image, s1, s2, s3, ans, movie = *ansinfo + +if number == ans then + print "<h2>罩hВ!!</h2>" + db.execute("REPLACE INTO point VALUES(?, ?)", + id, "quiz-" + quiz_mode + "-" + form_qn) # ex. quiz-kantan-1 + printf(<<-EOF, movie, quiz_mode, 1+form_qn.to_i) + <video controls autoplay width="320" height="240"> + <source src="%s"> + </video> + <p><input type="hidden" name="mode" value="%s"> + <input type="hidden" name="qn" value="%d"></p> + EOF + # form_qn 1泣 hidden 篁莨若 + if form_qn.to_i < q.length # 障罨< + puts('<p><input type="submit" value="罨<馹檎蚊"></p>') + else # 鴻腟篋 + puts("<p>с!</p>") + n_right = db.execute("SELECT count(*) FROM point WHERE id=?", id)[0][0] + printf(<<-EOF, n_question, n_right.to_i) + <p>с!</p> + <p>%d鋇 %d閫hВ障</p> + EOF + if n_question == n_right.to_i + puts("<p>∫!") + end + end +else + printf("<h1>膃%d</h1>\n", form_qn) + if /\d/ =~ number + puts("<h2>罧綽! 筝綺!</h2>") + end + printf("<p>") + imgsrc(image) + printf("</p>") + n=0 + for i in [s1, s2, s3] do + outinput((n+=1).to_s, i) # <input name="rd" ....> + puts("<br>") + end + printf(<<-EOF, quiz_mode, form_qn) + <input type="hidden" name="mode" value="%s"> + <input type="hidden" name="qn" value="%s"> + <p><input type="submit" value="篆"> + <input type="reset" value="祉"></p> + EOF +end +print"</form>\n" +print "</body>\n" +print "</html>\n"