view shuzai/ice/babychuchu/ajax.rb @ 3621:164395a050f4

add kuchikomi program
author ITO Shiho <c115022@g.koeki-u.ac.jp>
date Tue, 30 Jan 2018 16:22:17 +0900
parents
children
line wrap: on
line source

#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

require 'cgi'
require 'json'

#moare = "moare.js"
#bchu = "bchu.js"

c = CGI.new
s = c['shop']
name = c['name']
star = c['star']
comment = c['comment']
sjs = ''
inputs = {}

if s == "moare"
  sjs = 'moare.json'
elsif s == "bchu"
  sjs = 'bchu.json'
end

if star.to_i == 0
  star = 3
elsif star.to_i > 5
  star = 5
elsif star.to_i < 1
  star = 1
end

#p sjs
data = File.open(sjs) do |io|
  JSON.load(io)
end
inputs["name"] = name
inputs["star"] = star
inputs["comment"] = comment

if name != "" && star != "" && comment != ""
data.unshift(inputs)
end

poi = File.open(sjs, "w") do |file|
  str = JSON.dump(data, file)
end
#sleep(3)

print "Content-type: text/plain; charset=UTF-8\n\n"

#puts "#{s},#{name},#{star},#{comment}"
puts JSON.pretty_generate(data)

yatex.org