root/lang/ruby/coderepos_stat/coderepos-commit-ping.rb

Revision 3040, 0.7 kB (checked in by coji, 12 months ago)

lang/ruby/coderepos_stat: bug fix

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Id Date Author Rev URL
Line 
1#!/usr/bin/env ruby
2#
3# Author:: MIZOGUCHI Coji <mizoguchi.coji at gmail.com>
4# License:: Distribute under the same terms as Ruby
5#
6# $Id$
7#
8require 'yaml'
9require 'cgi'
10require 'date'
11
12cgi = CGI.new
13print cgi.header('type' => 'text/html; charset=utf-8')
14
15begin
16  exit unless cgi.has_key? 'yaml'
17  yaml = cgi['yaml']
18
19  y = YAML.load(yaml)
20
21  date = DateTime.parse(y['date'], '%Y-%m-%d %H:%M:%S %Z')
22  dir = "data/#{date.strftime('%Y%m%d')}"
23  Dir.mkdir(dir) unless FileTest.exist?(dir)
24
25  file = "#{dir}/commit-#{date.strftime('%H%M%S')}.yaml"
26  File.open(file, 'w') do |f|
27    f.print yaml
28  end
29
30  print "<html><body>yaml saved to <a href='#{file}'>#{file}</a></body></html>"
31rescue =>e
32  puts e
33  puts
34  puts e.backtrace
35end
Note: See TracBrowser for help on using the browser.