changeset 3375:bc44ddf6cfb7

プログラムを改良
author houtin <c115080@g.koeki-u.ac.jp>
date Wed, 26 Jul 2017 10:09:54 +0900
parents e997a921d44d
children 1effbb7c7027
files event/oasis2017/quiz/#cookie.rb# event/oasis2017/quiz/kantan.rb event/oasis2017/quiz/panelqr.rb event/oasis2017/quiz/qrpanel.rb
diffstat 4 files changed, 213 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event/oasis2017/quiz/#cookie.rb#	Wed Jul 26 10:09:54 2017 +0900
@@ -0,0 +1,43 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+
+require 'yaml/store'
+file = "db/point.yaml"
+
+require 'cgi'
+c = CGI.new(:accept_charset => "UTF-8")
+
+# ≪祉鴻ф≪cookie絎臂緇
+# 吟cookiec.cookies[紊医][0] у
+cookie_id=c.cookies["id"][0]
+
+# ≪祉鴻уュゃ緇
+form_name=c["playname"]        # name若緇()
+form_kwd=c["keyword"]          # keyword緇()
+
+
+if cookie_id == nil             # (1)cookieid井域
+  # 域id憜祉腱(to_i)絖(to_s)箙掩違腟水
+  newid = Time.now.to_i.to_s + "/" + rand(99999).to_s
+  id=newid                      # 域idid
+else                            # (2)cookieid違id
+  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 = YAML::Store.new(file)
+db.transaction do
+  info = db["info"] = db.fetch("info", Hash.new)
+  if !info[id]              # 若倶宴脂(腥)
+    info[id] = Hash.new     # 域激ャ蚊綵
+  end
+  if form_name > ""             # form荐絎
+    info[id]["name"] = form_name # 若倶宴荐
+
+
+end
\ No newline at end of file
--- a/event/oasis2017/quiz/kantan.rb	Tue Jul 25 21:51:16 2017 +0900
+++ b/event/oasis2017/quiz/kantan.rb	Wed Jul 26 10:09:54 2017 +0900
@@ -2,10 +2,50 @@
 # -*- coding: utf-8 -*- 
 
 require 'cgi'
+#require './panelqr.rb'
 
-qp = PanelQR.new
-c = CGI.new(:accept_charset => "UTF-8")
-print "Content-type: text/html; charset=UTF-8\n\n"
+require 'sqlite3'
+file = "db/users.sq3"
+
+
+
+
+
+#cookie≫
+cookie_id=c.cookies["id"][0]
+
+form_seikai=c["seikai"]  #罩hВ??
+
+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))")
+
+
+if form_seikai > "" && id > ''# 罩hВ
+  db.execute("DELETE FROM point WHERE id=?", id)
+end
+
+# cookie∫c障сc
+
+
+
+
 
 number = c["rd"]
 img = c["img"]
@@ -21,6 +61,22 @@
   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">
+</head>
+<body>
+
+EOF
+
+
+
+
+
+
 x = {"1" =>  ["<h1>膃筝<br></h1>", {"2" => "藏翫<br>", "3" => "ュ絮怨<br>", "4" => "蕋罍絮怨<br>"}],
   "2" =>  ["<h1>膃筝<br></h1>", {"2" => "藏翫<br>", "3" => "ュ絮怨<br>", "4" => "蕋罍絮怨<br>"}],
   "3" => ["<h1>罩hВ鐚鐚鐚鐚<br></h1>", "<p>祉荀眼ゆс祉祉</p>"],
@@ -69,19 +125,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>")
-    pq = regist(ゃゃID?,1)
+  #  pq = regist(ゃゃID?,1)
   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>")
-    pq = regist(ゃゃID?,2)
+ #   pq = regist(ゃゃID?,2)
   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>")
-    pq = regist(ゃゃID?,3)
+  #  pq = regist(ゃゃID?,3)
   end
   printf("<input type=\"submit\" value=\"罨<\">")
   
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event/oasis2017/quiz/panelqr.rb	Wed Jul 26 10:09:54 2017 +0900
@@ -0,0 +1,45 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*- 
+
+class PanelQR
+  def initialize(dbfile = "paneldb.yaml")
+    @db = YAML::Store.new(dbfile)
+  end
+  def regist(player, place)
+    @db.transaction do
+      # pn紊違<ゃ荐蚊宴緇
+      pn = @db["panel"] = @db.fetch("panel", Hash.new)
+      # 脂画(player)腥冴域Hash篁e
+      if pn[player] == nil
+        pn[player] = Hash.new
+      end
+      # playerplaceQR潟若緇
+      if pn[player][place] == nil then
+        pn[player][place] = 0# Hash.new(0)篏帥
+      end
+      pn[player][place] += 1
+    end
+  end
+  def list(player)
+    @db.transaction do
+      pn = @db["panel"]
+      # 宴腥冴с医阪
+      if pn && pn[player] then
+        pn[player].each do |place, count|
+          printf("%s  %s %d茵障\n", player, place, count)
+        end
+      end
+    end
+  end
+  def listall()
+    @db.transaction do
+      if @db["panel"] then
+        @db["panel"].each do |who, phash|
+          phash.each do |place, count|
+            printf("%s  %s %d茵障\n", who, place, count)
+          end
+        end
+      end
+    end
+  end
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/event/oasis2017/quiz/qrpanel.rb	Wed Jul 26 10:09:54 2017 +0900
@@ -0,0 +1,63 @@
+#!/usr/bin/env ruby
+# -*- coding: utf-8 -*-
+
+require 'yaml/store'
+
+player = ARGV[0]
+place  = ARGV[1]
+
+if player == nil then
+  STDERR.puts "#{$0} Player Place"
+  exit 1
+end
+
+class PanelQR
+  def initialize(dbfile = "paneldb.yaml")
+    @db = YAML::Store.new(dbfile)
+  end
+  def regist(player, place)
+    @db.transaction do
+      # pn紊違<ゃ荐蚊宴緇
+      pn = @db["panel"] = @db.fetch("panel", Hash.new)
+      # 脂画(player)腥冴域Hash篁e
+      if pn[player] == nil
+        pn[player] = Hash.new
+      end
+      # playerplaceQR潟若緇
+      if pn[player][place] == nil then
+        pn[player][place] = 0# Hash.new(0)篏帥
+      end
+      pn[player][place] += 1
+    end
+  end
+  def list(player)
+    @db.transaction do
+      pn = @db["panel"]
+      # 宴腥冴с医阪
+      if pn && pn[player] then
+        pn[player].each do |place, count|
+          printf("%s  %s %d茵障\n", player, place, count)
+        end
+      end
+    end
+  end
+  def listall()
+    @db.transaction do
+      if @db["panel"] then
+        @db["panel"].each do |who, phash|
+          phash.each do |place, count|
+            printf("%s  %s %d茵障\n", who, place, count)
+          end
+        end
+      end
+    end
+  end
+end
+pq = PanelQR.new
+
+if player == "-l" then
+  pq.listall
+else
+  pq.regist(player, place)
+  pq.list(player)
+end

yatex.org