Skip to content

Instantly share code, notes, and snippets.

@komasaru
Last active April 19, 2018 06:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save komasaru/ac9a9fffcb43072e90c133b6968500d7 to your computer and use it in GitHub Desktop.
Save komasaru/ac9a9fffcb43072e90c133b6968500d7 to your computer and use it in GitHub Desktop.
Ruby script to get a list of DUT1 adjustment.
#! /usr/local/bin/ruby
# coding: utf-8
#---------------------------------------------------------------------------------
#= Ruby script to get a list of DUT1 adjustment.
#
# date name version
# 2016.07.25 mk-mode 1.00 新規作成
#
# Copyright(C) 2016 mk-mode.com All Rights Reserved.
#---------------------------------------------------------------------------------
#
require 'kconv'
require 'nokogiri'
require 'open-uri'
require 'pp'
class GetDut1Nict
URL = "http://jjy.nict.go.jp/QandA/data/dut1.html"
UA = "mk-mode Bot (by Ruby/#{RUBY_VERSION}, Administrator: postmaster@mk-mode.com)"
def exec
dut1s = Array.new
begin
html = open(URL, "r:sjis", {"User-Agent" => UA}) { |f| f.read }.toutf8
doc = Nokogiri::HTML.parse(html)
doc.xpath("//pre").text.split("\n").each do |line|
l = line.scan(/(.+?)年 ?(.+?)月(.+?)日 0900 JST から(.+?)秒$/)[0]
next unless l
dut1s << (l[0,3].map { |a| NKF::nkf("-WwZ1", a).to_i } << NKF::nkf("-WwZ1", l[-1]).to_f)
end
pp dut1s.sort
rescue => e
msg = "[#{e.class}] #{e.message}\n"
msg << e.backtrace.map { |tr| "\t#{tr}\n" }.join("\n")
$stderr.puts msg
end
end
end
GetDut1Nict.new.exec if __FILE__ == $0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment