view ruby/pro2.rb @ 501:2711c888d31e

merge
author TAGUCHI Ayae<c112093@h.koeki-u.ac.jp>
date Wed, 19 Feb 2014 06:50:01 +0900
parents 67e5ccca9f78
children
line wrap: on
line source

#!/usr/koeki/bin/ruby
# coding: euc-jp

require 'fileutils'
time = Time.now

if ARGV[0] == nil
  STDERR.print "./pro2.rb 生成するファイル名.html で起動してください\n"
  exit(1)
end

name = ARGV[0].to_s

open(name, "w") do |out|   
  css = ["syuzai", "enq", "other"]
  x = 0
  STDERR.print "取材した店(番号を選択)\n"
  STDERR.print "1.取材、伝説 2.アンケート調査:"
  sentaku = STDIN.gets.chomp.to_i
  choice = css[sentaku-1]
  
  STDERR.print "店の名前:"
  sbj = STDIN.gets.chomp
  
  history = ""
  STDERR.print "歴史(return 2回押して終了)\n"
  while true
    his = STDIN.gets
    if his == "\n" || his == nil then
      break
    end
    history += his
  end
  
  regend = ""
  STDERR.print "伝説(return 2回押して終了)\n"
  while true
    reg = STDIN.gets
    if reg == "\n" || reg == nil then
      break
    end
    regend += reg
  end
  
  STDERR.print "おすすめ品\n"
  osu = STDIN.gets.chomp
  
  STDERR.print "郵便番号(半角)\n"
  yu = STDIN.gets.chomp
  
  STDERR.print "住所\n"
  add = STDIN.gets.chomp
  
  STDERR.print "電話番号(半角)\n"
  tel = STDIN.gets.chomp
  
  STDERR.print "写真をアップロード\n"
  STDERR.print "元の画像を選んでください:"
  before = STDIN.gets.chomp
  
  STDERR.print "保存する画像の名前を決めてください:"
  after = STDIN.gets.chomp
  `convert -geometry 150x100 #{before} #{after}`
  STDERR.print "画像はsyuzai/ に保存します。\n"
  FileUtils.mv(after, '../syuzai/')

  #STDERR.print "保存先を指定してください\n"
  #save = STDIN.gets.chomp
  FileUtils.mv(name, '../syuzai')
  STDERR.print "ファイルは../syuzai に保存されました\n"  
  
  open("temp.txt", "r") do |cm|
    while x = cm.gets
      x.gsub!("%choice%", choice)
      x.gsub!("%time%", time.to_s)
      x.gsub!("%sbj%", sbj)
      x.gsub!("%after%", after)
      x.gsub!("%history%", "<pre>"+history.chomp+"</pre>")
      x.gsub!("%regend%", "<pre>"+regend.chomp+"</pre>")
      x.gsub!("%osu%", osu)
      x.gsub!("%yu%", yu)
      x.gsub!("%add%", add)
      x.gsub!("%tel%", tel)
      out.print x
    end
  end
end

yatex.org