#!/usr/bin/ruby require 'time' class App def help $stderr.puts "usage: #$0 [-opts] maptime outfile.(json|html) [zsort.txt ...]" exit 16 end def initialize argv @flags = {} while /^-(\w+)(?:[:=](.*))?/ === argv.first argv.shift @flags[$1] = ($2 || true) end maptime = argv.shift help if maptime.nil? @outfile = argv.shift @files = argv @maptime = Time.parse(maptime).utc @level = 'sfc' @merge = {} rescue => e $stderr.puts "#{e.class}: #{e.message}" help end def htmlhead windbase = (@flags['WD'] || 'https://raw.githubusercontent.com/etoyoda/wxsymbols/master/img/') wxbase = (@flags['WX'] || @flags['WD'] || 'https://toyoda-eizi.net/wxsymbols/') bt = @maptime.strftime('%Y%m%d%H%M%S') < bufrsort #{@maptime} #{@level}
map will be here
HTML end def outjson io io.puts '[' first = true @merge.each {|k, v| io.puts(v + ',') } io.puts '{"@":"dummy"}]' end def iopen if @files.empty? then yield $stdin else @files.each{|fnam| File.open(fnam, 'r:UTF-8') {|fp| yield fp } } end end def oopen case @outfile when nil, '-' then yield $stdout else File.open(@outfile, 'w:UTF-8') {|fp| yield fp } end end def run pat = @maptime.utc.strftime('^%Y-%m-%dT%H:%MZ/') + @level pattern = Regexp.new(pat) n = 0 iopen() {|fp| fp.each_line{|line| next unless pattern === line n += 1 k, v = line.chomp.split(/ /, 2) @merge[k] = v } } $stderr.puts "#{n} lines" if $VERBOSE oopen() {|ofp| ofp.write htmlhead if /\.html?$/ === @outfile outjson(ofp) ofp.write htmltail if /\.html?$/ === @outfile } end end $VERBOSE = true if $stderr.tty? App.new(ARGV).run