Last active
April 19, 2018 06:30
Revisions
-
komasaru revised this gist
Apr 19, 2018 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -38,5 +38,4 @@ def exec end end GetLeapcecNict.new.exec if __FILE__ == $0 -
komasaru revised this gist
Jul 25, 2016 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -12,6 +12,7 @@ require 'kconv' require 'nokogiri' require 'open-uri' require 'pp' class GetLeapcecNict URL = "http://jjy.nict.go.jp/QandA/data/leapsec.html" @@ -28,7 +29,7 @@ def exec next unless l leapsecs << l.map { |a| NKF::nkf("-WwZ1", a).to_i } end pp leapsecs.sort rescue => e msg = "[#{e.class}] #{e.message}\n" msg << e.backtrace.map { |tr| "\t#{tr}\n" }.join("\n") -
komasaru created this gist
Jul 25, 2016 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,41 @@ #! /usr/local/bin/ruby # coding: utf-8 #--------------------------------------------------------------------------------- #= Ruby script to get a list of leap-second 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' class GetLeapcecNict URL = "http://jjy.nict.go.jp/QandA/data/leapsec.html" UA = "mk-mode Bot (by Ruby/#{RUBY_VERSION}, Administrator: postmaster@mk-mode.com)" def exec leapsecs = [[0, 1972, 1, 1, -10]] 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(/[\s ]+(.+?)[\s ]+(.+?)[\s ]*年[\s ]*(.+?)[\s ]*月[\s ]*(.+?)[\s ]*日.+?秒[\s ]*(.+?)[\s ]*秒$/)[0] next unless l leapsecs << l.map { |a| NKF::nkf("-WwZ1", a).to_i } end p leapsecs.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 exit 0 unless __FILE__ == $0 GetLeapcecNict.new.exec